I want to select second class value with jquery. For example;
<div class="mb-20"></div>
How can i get "20" value after from "mb-" ?
Here a sample of what you need, to illustrate i made this when you click the div.
// The selector just get all class starting with mb
$('[class^="mb"]').on('click', function() {
alert($(this).attr('class').split('-')[1]);
});
And here is the FIDDLE
If you have already selected the div you can iterate over its classes, and split each class on hyphen. Something like...
$.each($('div').attr('class').split(/s+/), function(idx, val) {
var parts = val.split('-');
var classBase = parts[0];
var classModifier = parts.length > 1 ? parts[1] : null;
if(classModifier !== null) alert("found class modifier" + classModifier);
});
If divs have more than one class, you can do this:
$('[class^="mb"]').on('click', function() {
alert($(this).attr('class').split(' ')[0].split('-')[1]);
});
This will get first class of element first, second, split it with - and return the number.
20, you can do$('[class$="20"]')