SilverLight
SilverLight

Reputation: 20468

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)

Upvotes: 18

Views: 40654

Answers (3)

Steve Wellens
Steve Wellens

Reputation: 20620

Maybe you are looking for the adjacent sibling selector:

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

Upvotes: 2

JohnP
JohnP

Reputation: 50019

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');

Upvotes: 23

Dejan Marjanović
Dejan Marjanović

Reputation: 19380

$("#element").find("div").text("Hello");

Upvotes: 1

Related Questions