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); }); 

js fiddle demo.

incidentally, class reserved word in javascript , should, or can, not used variable name (i believe error thrown if so).

references:


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -