开发者

Jquery target span after current element

开发者 https://www.devze.com 2023-02-11 01:39 出处:网络
I want to find the next instance of an element at the same level. <div id=\"foo\"></div> <some html />

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

精彩评论

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