javascript - JQuery get the rest of the element's class name that starts with string "whatever-" -


i have js caches classes that's name starts "whatever-",

$('[class^="whatever-"], [class*=" whatever-"]') 

but want rest of name, example in case of "whatever-9" want "9", don't know how it, can me?

try this

var check = "whatever-";              $('[class^="whatever-"], [class*=" whatever-"]').each(function () {             // array of class names            var cls = $(this).attr('class').split(' ');                (var = 0; < cls.length; i++) {             // iterate on class , log if matches             if (cls[i].indexof(check) > -1) {                         console.log(cls[i].slice(check.length, cls[i].length));             }                }         }); 

this should work case when there more 1 class. there may cleaner ways of doing using filter method , bit of regex

check fiddle

a little cleaner using map

var check = "whatever-"; $('[class^="whatever-"], [class*=" whatever-"]').each(function () {     var classname = this.classname;      var cls = $.map(this.classname.split(' '), function (val, i) {         if (val.indexof(check) > -1) {             return val.slice(check.length, val.length)         }     });      console.log(cls.join(' ')); }); 

map demo


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -