jQuery 使用jQuery在特定元素之后查找元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5848762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:54:38  来源:igfitidea点击:

Finding an element after a specific element using jQuery

jqueryselector

提问by SilverLight

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)

使用 jQuery 选择器,如何div在另一个特定元素之后立即找到一个元素,例如?(不是兄弟,next()在这种情况下无法帮助)

回答by JohnP

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

使用nextAll()带有过滤器:http://api.jquery.com/nextAll/

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

这是一个演示:http: //jsfiddle.net/JRPGh/1/

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


$('.start').nextAll('.start:first').css('background', 'red');

回答by Steve Wellens

Maybe you are looking for the adjacent sibling selector:

也许您正在寻找相邻的兄弟选择器:

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

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

回答by Dejan Marjanovic

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