Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Since jquery uses CSS selectors, as defined by the CSS specification a selector with multiple conditions will look like:

$('div[attr1="value1"][attr2="value2"]')

see the CSS spec for further reference: http://www.w3.org/TR/CSS2/selector.html#matching-attrs

@JitendraPancholi: where exactly did you get that idea? I cited the exact place in the documentation that supports my statement. If you are going to refute what I said (and vote me down), I would at least expect a courtesy of a reference to something official. – Dmitry B. Apr 2, 2018 at 22:36 I tried your code in my project and found it not working. I did it practically and don't have any other reference. – Jitendra Pancholi Apr 4, 2018 at 10:33 @JitendraPancholi: So in 7 years, 31,000 views and 59 upvotes, you are the first one to say this answer is wrong. Can you explain? – Dmitry B. Apr 4, 2018 at 22:52 jQuery documentation says clearly "Matches elements that match all of the specified attribute filters" so yes it is an AND and not an OR and this is the correct answer. api.jquery.com/multiple-attribute-selector – David Kolar Jun 30, 2020 at 15:53 @Geek It wasn't correct when I added my comment. Seeing that the answer has since been edited and fixed, I'll delete the comment to avoid any confusion. – Daniel Liuzzi Jun 21, 2021 at 21:19

To select multiple attributes, see the code below.

This code will find all inputs that have an id attribute and whose name attribute ends with 'man' and sets the value.

$( "input[id][name$='man']" ).val( "this input has id and name ends with 'man'" );

You can even target an element like so:

const elem = $('.className[type="checkbox"][name="someName"]')

or in more dynamic way with a parameter:

const elem = $('.elemClassName_'+$(this).data('id')+'[type="checkbox"][name="someName"]')

I use the last example to target a checkbox when an input value changes. The above is from many examples, and they work for me.

$("#a .b")  = <div id="a"><div class="b">..

If you use without space it take same object with 2 class

$("#a.b")  = <div id="a" class="b">..
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.