0
jQuery Traversing
Why is the following alert 2 and not 1 ?? <div><p>1</p></div> <div>2</div> <script> alert($("p").parent().siblings().eq(0).text()); </script>
2 Antworten
+ 13
When you use siblings() it selects all of them on that level but doesn't includes the one you're initially selecting. So in this case, you selected the <p> parent which is the first div listed. Now the only sibling is the second div with the number 2. So that would be at position 0.
0
thank you sir ! clean and to the point