fatiDev fatiDev - 1 year ago 194
jQuery Question

get element specific class that starts with

i have a list of element that have multiple classes for example

<input class="etape btn-info others">
<input class="etape btn-inverse others">
<input class="etape btn-danger others">

How to write jquery code that will allows me the following ,

$(this).get("the class that starts with btn-")
// in order to store this value in a variable to reuse it later

Answer Source

You can use Regular Expression or split the class name.

   var get = $.grep(this.className.split(" "), function(v, i){
       return v.indexOf('btn') === 0;


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download