How to select dynamic data attribute element in jquery
I have many elements like
<input tag="data-initial-222" value="" type="checkbox">
<input tag="data-initial-111" value="" type="checkbox">
How can I select all elements that have this "data-initial - *" tag
Another question:
How to choose
<input data-initial="111" type="checkbox">
or
<input data-initial="222" type="checkbox">
using the data-initial attribute.
+3
source to share
2 answers
console.log($("input[data-initial]").length)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input tag="data-initial-222" value="" type="checkbox">
<input data-initial="111" value="" type="checkbox">
<input data-initial="222" value="" type="checkbox">
<input data-initial="333" value="" type="checkbox">
Description: Selects elements with the specified attribute with a value that starts exactly at the specified string.
- Attribute selector
Description: Selects elements with the specified attribute with any value.
+2
source to share