简体   繁体   English

什么是jQuery选择器,用于在特定div中选择具有特定类的锚元素

[英]What is the jQuery selector for selecting anchor elements with a particular class in a particular div

I have some code like this and I want to select every <a> tag with the class status in the div foo 我有一些像这样的代码,我想在div foo选择每个具有类status <a>标签

<div id="foo">
...
<a class = "status"> ... </a>
...
</div>

你可以这样做$('#foo').find('.status')

选择器将是:

$("#foo a.status");

Try this and read this : 试试这个,看这个

$("#foo a.status")

Good luck! 祝好运!

这有效。

$("#foo").find("a.status")

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.statusdiv#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')

try with 尝试

$('div#foo > a.status')

it selects the anchors which are DIRECT children of div #foo 它选择了div #foo的DIRECT子节点的锚点

Try this: 尝试这个:

$('div#foo a.status')

The docs are here 文档在这里

jQuery('#foo')     //select elm with id foo
.find('a.status')  //find anchor with class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM