Jquery: Select An Element When Two Or More Conditions Are True
I have an element like this
- li and class
myclasswould be:li.myclassto find by attribute, use
[attribute=x], so to combine the two:li[data-id=45][data-ud=322]or, with jquery:
$("li[data-id=45][data-ud=322]")This can be difficult to read and prone to errors eg a space between the two
[][]will give a totally different result, so you can instead usefilterto the same effect:$("li").filter("[data-id=45]").filter("[data-ud=322]")Fiddle example: https://jsfiddle.net/o9fdhphf/
Solution 2:
Try the following:
$('li[data-id=45][data-ud=322 ]');
Post a Comment for "Jquery: Select An Element When Two Or More Conditions Are True"