jquery - field with multiple classes will if statement match -


this question has answer here:

if have field has multiple classes:

<input type='text' class='req small inside' id='car'> <input type='text' class='req small inside' id='truck'> <input type='text' class='small inside' id='boat'> 

will if statement below match id car , truck?

 $.each($('.inside'),function(){       if ($(this).attr('class') == "req"){            //do something;       }  }); 

if alert($(this).attr('class') result req small inside car , truck , small inside boat

you use .hasclass() check it.

 $('.inside').each(function(){       if ($(this).hasclass('req')){            //do something;       }  }); 

and in selector.

// elements class 'inside' , 'req' @ same time. $('.inside.req').each(function() {   // }); 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -