Search code examples
jquerydomjquery-selectorscss-selectors

jQuery: select an element's class and id at the same time?


I've got some links that I want to select class and id at the same time.

This is because I've got 2 different behaviours. When a class of links got one class name they behave in one way, when the same clas of links got another class name they behave differently. The class names are switch with jquery.

So I have to be able to select a links class AND id at the same time. Is this possible?

I've tried:

 $("a .save #country")

without any result.


Solution

  • You can do:

    $("#country.save")...
    

    OR

    $("a#country.save")...
    

    OR

    $("a.save#country")...
    

    as you prefer.

    So yes you can specify a selector that has to match ID and class (and potentially tag name and anything else you want to throw in).