javascript - how to get [x,y] position related to the clicked div border? -


how [x,y] position related clicked div border?

this position of clicked box random , example bellow 1 situation. want click point position related clicked div , how in js ?

<!doctype html> <html lang="en-us"> <head>     <meta charset="utf-8">     <title>img click positon</title> </head> <body>     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>     <script type="text/javascript">         $(function(){             $('.clickbox').bind('click',function(e){                 // how [x,y] positon relatived div.clickbox ?                 // console.log(x,y);             })         });     </script>     <style type="text/css">         *{margin:0;padding:0}         .page{margin:0 auto; width:940px}         .box{width:200px; margin:0 auto; margin-top:10%}         .clickbox{width:100%; height:230px;background-color:tan;}     </style>     <div class="page">         <div class="box">             <div class="clickbox"></div>         </div>     </div> </body> </html> 

enter image description here

$('div.clickbox').click(function(e) {     var offset = $(this).offset();     console.log("x: "+e.clientx - offset.left);     console.log("y: "+e.clienty - offset.top); }); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -