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
Post a Comment