I want to find and select all element which have data attribute start with "data-qu" under wrapper div. How can I do this with using jquery?
HTML
<div class="wrapper">
<div data-qu-lw="1"></div>
<div data-qu-md="2"></div>
<div data-res-kl="1"></div>
<div data-qu-lg="3"></div>
</div>
Is there a way select those, like this $('.wrapper').find('^data-qu')
or similar?
var filteredElements = $('.wrapper > div').filter(function(){
var attrs = this.attributes;
for (var i=0; i<attrs.length; i++) {
if (attrs[i].name.indexOf("data-qu")==0) return true;
}
return false;
});
ref: jQuery attribute name contains
you can do like this.
$('.wrapper div').filter(function() {
for (var property in $(this).data()) {
if (property.indexOf('data-qu') == 0) {
return true;
}
}
return false;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With