I have a list of elements that have multiple classes, for example:
I just made @Vohuman 's function to reusable one :
// getClassStartsWith(classes,startswith);
// Example : getClassStartsWith( 'item w-2 h-4 hello' , 'h-' );
function getClassStartsWith(t,n){var r=$.grep(t.split(" "),function(t,r){return 0===t.indexOf(n)}).join();return r||!1}
Example...
HTML :
JS :
var $element = $('.item');
var classes = $element[0].className;
var getHeight = getClassStartsWith(classes,'h-');
That will return h-4
, And if no class starts with h-
will return false
Demo : http://jsbin.com/mijujunaca/edit?js,console