Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
68
rated 0 times [  70] [ 2]  / answers: 1 / hits: 5056  / 10 Years ago, mon, april 28, 2014, 12:00:00

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?


More From » jquery

 Answers
6

here is how



if ($('[data-attr^=123]').length > 0) { 
//do something
}

[#45703] Saturday, April 26, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jesse

Total Points: 513
Total Questions: 118
Total Answers: 106

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
;