I am trying out the following code:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("span").click(function(){
alert($(this).offsetParent().length);
});
});
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p><span>Click me away!</span></p>
<p>Click me too!</p>
</body>
</html>
From the jQuery documentation, offsetParent()
is supposed to return the closest positioned parent, positioned meaning one with position
defined explicitly as 'static,
absoluteor
relative`. here, none is declared for any element, yet the alert pops up 1. How come?