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

24,958

Solution 1

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

Solution 2

The selector would be:

$("#foo a.status");

Solution 3

Try this and read this:

$("#foo a.status")

Good luck!

Solution 4

This works.

$("#foo").find("a.status")
Share:
24,958
abc def foo bar
Author by

abc def foo bar

Updated on December 19, 2020

Comments

  • abc def foo bar
    abc def foo bar over 3 years

    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>
    
  • Alex
    Alex about 13 years
    A note: This will select only the anchors with a class of status that are direct children of the div with an id of foo. This may be what the OP was after, I just wanted to provide clarity here.
  • Mauricio
    Mauricio about 13 years
    @Alex thanx, I'll add that to the answer
  • Gonzalo Larralde
    Gonzalo Larralde about 12 years
    hasClass returns boolean, not the elements that actually has the class. Anyway, the link is great.