forkhyun (27) [Avatar] Offline
#1
Hi,

I was looking at the example of position() to understand it better. However the result of executing this example didn't show me the right answer.

The example on the jquery website said that the results are left: 15 right:15.

When I executed it, it gave me left: 23 right:23.

Please look at the example below:

<!DOCTYPE html>
<html>
<head>
<style>

div { padding: 15px;}
p { margin-left:10px; }
</style>
<script src="http://code.jquery.com/jquery-1.6.3.min.js"></script>
</head>
<body>

<div>

Hello



</div>



<script>
var p = $("p:first");
var position = p.position();
$("p:last").text( "left: " + position.left + ", top: " + position.top );
</script>

</body>
</html>

I am sorry to raise a question about the example that this book isn't covering. I just wanted to know why it happens...

My assumption is that the nearest ancestor, div, doesn't have either "position:relative" or "position:absolute". So the figures are measured from at the edges of window browser. Is that correct?


Thanks again for your help.



p.s I put back slashes infront of p elements as they are not showing up on this forum message.