here is how
if ($('[data-attr^="123"]').length > 0) {
//do something
}
Pregunta
I want to be able to check to see if a specific data attribute exists that starts with a specific value.
for example lets say i have the following HTML code:
<div data-attr="123ABC"></div>
<div data-attr="123456"><div>
<div data-attr="TEST"></div>
and then i want to find any use of the data tag of data-attr
that starts with 123
if ($('[data-attr="123"]').length > 0) {
//do something
}
This appears to always return 0
as i have no data-attr="123"
How would i make it so i can check for only that specific data attribute that starts with 123 and has anything after that?
Solución
here is how
if ($('[data-attr^="123"]').length > 0) {
//do something
}