Javascript 什么是用于在特定 div 中选择具有特定类的锚元素的 jQuery 选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5062989/
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
What is the jQuery selector for selecting anchor elements with a particular class in a particular div
提问by abc def foo bar
I have some code like this and I want to select every <a>
tag with the class status
in the div foo
我有一些这样的代码,我想在 div 中选择<a>
带有类的每个标签status
foo
<div id="foo">
...
<a class = "status"> ... </a>
...
</div>
回答by Hussein
You can do this $('#foo').find('.status')
你可以这样做 $('#foo').find('.status')
回答by Alex
The selector would be:
选择器将是:
$("#foo a.status");
回答by Adeel
This works.
这有效。
$("#foo").find("a.status")
回答by Praveen Prasad
jQuery('#foo') //select elm with id foo
.find('a.status') //find anchor with class
回答by challet
There is no such thing as a "jQuery selector", what you mean is :
没有“jQuery 选择器”这样的东西,你的意思是:
either CSS selector:
任一CSS 选择器:
In that case the answer is div#foo a.status
or also div#foo > a.status
(depending if there are intermediate containers)
在这种情况下,答案是div#foo a.status
或也是div#foo > a.status
(取决于是否有中间容器)
or jQuery functions:
或jQuery 函数:
In that case there are several ways to do it :
在这种情况下,有几种方法可以做到:
$('div#foo a.status')
$('div#foo > a.status')
$('div#foo').find('a.status')
$('div#foo').children('a.status')
$('div#foo a.status')
$('div#foo > a.status')
$('div#foo').find('a.status')
$('div#foo').children('a.status')
回答by Mauricio
try with
尝试
$('div#foo > a.status')
it selects the anchors which are DIRECT children of div #foo
它选择作为 div #foo 的 DIRECT 子级的锚点