I have a situation. I am using web application of windows(ASP.NET). On page load when my web page appears, it has dynamically generated ImageButtons. I need to fid the X,Y or TOP,LEFT co-ordinates of each ImageButton control on the page WITHOUT CLICKING ON ANY OF THE ImageButtons.. I need to draw a line beetween some ImageButtons on the click of one ImageButton.
Try using some Javascript code or jQuery. Please find below jQuery code
Here i have used position() method which gives you left and top position of the element. You can change the selector based on your need.
Update : Assumed you have HTML like <div id='images-container'> .. all images here </div>
and updated selector below for that with each() method
You can also use offset()
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#images-container img').each(funcion(){
var coordinates=$(this).position();
coordinates.left;// gives you x
coordinates.top;// gives you y
//save these values in some hidden field and access it in code behind if needed
});
});
</script>
Please refer this post for more information jQuery xy document coordinates of DOM object
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.