Jquery: Select An Element When Two Or More Conditions Are True
I have an element like this
- li and class
myclass
would be:li.myclass
to 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 usefilter
to 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 ]');
Solution 3:
$("[data-ud=322][data-id=45]").text()
OR
$("[data-ud=321] + [data-id=45]").text()
Post a Comment for "Jquery: Select An Element When Two Or More Conditions Are True"