开发者

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜