Reputation: 27048
How to get an element by data attribute when there are multiple values for the same attribute ?
<a data-multiplevalues="valuea valueb valuec">Test</a>
$("a[data-multiplevalues='valuea valueb valuec']") - works
$("a[data-multiplevalues='valuea']") - doesn't work
Any ideas?
Upvotes: 1
Views: 713
Reputation: 97682
For [data-multiplevalues='valuea']
the attribute has to be exactly equal to the value, if you want to select an element with an attribute that contains white space separed values you can use
a[data-multiplevalues~='valuea']
See http://www.w3.org/TR/selectors/#attribute-selectors for more
Upvotes: 0
Reputation: 148150
You are using attribute equality selector so you need exact match. You can use *
to get the elements that contains the string in given attribute value. If the string you are looking in expected in the start then you can use starts with selector using ^
instead of using *
You can read more about the wild card selector here.
$("a[data-multiplevalues*='valuea']")
Upvotes: 1