最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the jQuery selector for selecting anchor elements with a particular class in a particular div - Stack Overf

programmeradmin1浏览0评论

I have some code like this and I want to select every <a> tag with the class status in the div foo

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

I have some code like this and I want to select every <a> tag with the class status in the div foo

<div id="foo">
...
<a class = "status"> ... </a>
...
</div>
Share Improve this question edited Dec 18, 2013 at 11:07 BenMorel 36.5k51 gold badges205 silver badges335 bronze badges asked Feb 21, 2011 at 6:31 abc def foo barabc def foo bar 2,3886 gold badges30 silver badges42 bronze badges 1
  • Looks like you forgot a closing quote – Andrew Marshall Commented Feb 21, 2011 at 6:34
Add a comment  | 

8 Answers 8

Reset to default 6

You can do this $('#foo').find('.status')

The selector would be:

$("#foo a.status");

Try this and read this:

$("#foo a.status")

Good luck!

This works.

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

Try this:

$('div#foo a.status')

The docs are here

try with

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

it selects the anchors which are DIRECT children of div #foo

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

There is no such thing as a "jQuery selector", what you mean is :

either CSS selector :

In that case the answer is div#foo a.status or also div#foo > a.status (depending if there are intermediate containers)

or jQuery functions :

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')

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论