dom - jquery nextALL traversal -


<div><a href="" class="deletenextsomething">delete something!</a></div> <div class="something">this something</div> 

obviously, this:

$('.deletenextsomething').click(function() {  $(this).parent('div').next('.something').remove(); }); 

but, if html more this:

<div><div><div><a href="" class="deletenextsomething">delete something!</a></div></div></div> <div class="something">this something</div> 

point is, don't want know how many parents need go before start going across. want traverse dom in "next" direction" until hit next node i'm looking for.

does know how solve this? pleasssse.

additional info. in next example, want delete something1. can't parents('div').next - because ignore next element.

<div>     <a href="" class="deletenextsomething">delete something!</a>     <div class="something">this 1</div> </div> <div class="something">this 2</div> 

if want @ "nearest" next, this, using .parents() go all parents, instead of first level:

$('.deletenextsomething').click(function() {   $(this).parents('div').next('.something:first').remove(); }); 

you can test out here. since they're in reverse order after .next() call, want :first 1 finds, local this started with.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -