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
–
–
–
–
–
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.