Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Getting "secondary" class

I'm using jQuery to loop through some elements in a document. These elements are of type <tr> with class .input-row. Some of the elements can also have a secondary class (for example .input-area).

I use $(".input-row").each() to loop through the elements, but how can I determine if the $(this)-element has a "secondary" class and if so, get the name of this?

like image 262
Christian Tang Avatar asked Jun 02 '26 16:06

Christian Tang


1 Answers

$(".input-row").each(function(){
  $.each($(this).attr('class').split(/\s+/), function(i, v){
    if(v !== 'input-row'){
      alert(v);
    }
  });
});
like image 51
michaeljdennis Avatar answered Jun 05 '26 06:06

michaeljdennis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!