javascript - I want to get part of the class of a clicked element in jQuery -
so, have function this:
$('a.tdt-btn-*').click(function() { var class = $(this + "[class^=tdt-btn-*]"); // need more here console.log(class); });
what want value of wildcard part @ end. how this?
i'd suggest:
$('a[class*=tdt-btn-]').click(function() { var elclasses = this.classname.split(/\s+/), elclasswildcard; (var = 0, len = elclasses.length; < len; i++){ if (elclasses[i].indexof('tdt-btn-') === 0) { elclasswildcard = elclasses[i].replace('tdt-btn-', ''); } } console.log(elclasswildcard); });
incidentally, class
reserved word in javascript , should, or can, not used variable name (i believe error thrown if so).
references:
Comments
Post a Comment