I want to select some html elements with name starting with btn (btn1, btn2..)
what is the most efficiant way to do that
I try http://james.padolsey.com/javascript/regex-selector-for-jquery/ but dont manage to make it work
$(':regex(class,btn[0-9]').hover( function(){
// not selecting any "btn" class
}
If you want to select all elements that have a class
attribute that starts with the word btn
:
$( '[class^=btn]' )
If you want to use the name
attribute instead, just swap out the attribute:
$( '[name^=btn]' )
Using the attribute value starts-with selector: http://api.jquery.com/attribute-starts-with-selector/
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