Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding an element after a specific element using jQuery

Using jQuery selectors, how to find an element, such as div, immediately after another specific element? (not sibling, next() can not help in this situation)

like image 401
SilverLight Avatar asked May 01 '11 13:05

SilverLight


2 Answers

Use nextAll() with a filter : http://api.jquery.com/nextAll/

Here's a demo : http://jsfiddle.net/JRPGh/1/

<div class='start'></div>
<div></div>
<div></div>
<div class='start'></div>


$('.start').nextAll('.start:first').css('background', 'red');
like image 150
JohnP Avatar answered Oct 14 '22 15:10

JohnP


Maybe you are looking for the adjacent sibling selector:

http://www.w3.org/TR/CSS2/selector.html#adjacent-selectors

like image 21
Steve Wellens Avatar answered Oct 14 '22 13:10

Steve Wellens