jquery offset() and position() -
i need position of element relative parent. position()
suppose looks doesn't.
<!doctype html> <html> <head> <style> body{padding: 0px; margin: 0px;} div { margin-left: 200px; padding: 30px; border: 1px solid red;} p { margin: 0px; padding: 0px; border: 1px solid black } </style> <script src="http://code.jquery.com/jquery-1.5.js"></script> <script> $(document).ready(function() { var p = $("p.paragraf"); var position = p.offset(); $("p.zadnji").text( "left: " + position.left + ", top: " + position.top ); }); </script> </head> <body> <div class="container"> <p class="paragraf">hello</p> </div> <p class="zadnji"></p> </body> </html>
result:
left: 231, top: 31
if p.paragraf
inside #container
#container
should parent p.paragraf
. if padding of #container
set 30px, shouldn't both left , top position of p.paragraf
30px?
i tried offset()
gives same result position()
Comments
Post a Comment