If you had a parent div nested inside another parent div and you wanted to get the next sibling of the first one, you could filter the parents() selector like so:

$(this).parents('div:first').next("div").toggle();

That will select the first div it finds as it goes from "this" up to its parent and grandparent and great-grandparent and so on. Then from there it will select the next sibling div.

--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Feb 17, 2008, at 8:59 AM, Daniele wrote:


Ok, I found the way, but I guess I need to understand more why it
works :-(

<div>
   <a href="">click</a>
</div>
<div> xxxx </div>

Solution is:

$(this).parents().next("div").toggle();

I used "parents" instead of "parent" because the real real html I am
using is:

<div>
   <span>
      <p><a href="#">click</a></p>
   </span>
</div>
<div> xxxx </div>

So as far as I understood, "parents" give me a list of elements
ordered from the starting element to "html" and next "move me" to the
next element used as parameter ... Like if i Had another <div> after
<p> between the <span> I had to move to the .nextAll().eq(1) element,
the second <div> in the list returned by "parents" ..

Is that right thinking like this? :-) ..

Thanks for pointing me to the solution.

d.


Reply via email to