Question: I'm looking for a way using jquery/javascript to get a class name when I only know part of it and there are more than one classes applied to that element.

So if I'm looking for a class that I know starts with "charLimit\_" I want to know that full class name even when it's not the only class applied to a given element.
Example HTML would be.

```
<input class="charLimit_30 lastNameValidation" type="text" />

```

What I have so far below will put both "charLimit\_30" and "lastNameValidation" into an array, but how do I then say I only want "charLimit\_30" and then only tell me the value found after the underscore (30).

```
var classMName = $('[class*=charLimit_]').attr("class").split(' ');

```

Thanks in advance for you help!!!

Answer: 
This appears to work (at least on stackoverflow):

```
var test = $('[class*=owner]').attr('class').split(' ');
for(i in test){
    if(test[i].indexOf('post-sign') !== false){
        test = test[i].split('-');
        // replace this with a return
        console.log(test[1]);
        break;
    }
}

```

And one that will work with the code that he is trying to do it with:

```
var test = $('[class*=charLimit_]').attr('class').split(' ');
for(i in test){
    if(test[i].indexOf('charLimit_') !== false){
        test = test[i].split('_');
        // replace this with a return if it is in a function
        console.log(test[1]);
        break;
    }
}

```
```
var classes = $('input').attr('class');
var myNum = '';
for(var i=0;i<classes.length;i++){
    if(classes[i].match(/^charLimit_.*$/){
        myNum = classes[i].split('_')[1];
    }
}

```

Something like that would work, unless of course there's some jQuery magic way of doing it that I'm simply unaware of :)