Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery regex selector

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

}
like image 914
Nico AD Avatar asked Apr 20 '11 16:04

Nico AD


1 Answers

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/

like image 184
Eli Avatar answered Sep 17 '22 16:09

Eli