Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery target span after current element

I want to find the next instance of an element at the same level.

<div id="foo"></div>
<some html />
<span></span>

<div id="foo2"></div>
<span></span>

What jQuery selector would allow me to target the next span for foo and then foo2. I took a look into next, siblings and closest, but I couldn't get anything to work.

like image 838
mrtsherman Avatar asked Feb 16 '11 15:02

mrtsherman


1 Answers

Use .nextAll() together with the :first selector:

$('#foo').nextAll('span:first')

Alternatively, use the next siblings selector ~ (known in CSS3 as the general sibling selector) together with the :first selector:

$('#foo2 ~ span:first')

Preview both on jsFiddle

like image 58
BoltClock Avatar answered Oct 10 '22 11:10

BoltClock