I am trying to write an if else
statement in JQuery, which can change an element's class by matching 'IN'
or 'OUT'
.
For example: I have several <DIV>
tags that each have class='IN-something'
or class='OUT-something'
.
The below would work if I knew the exact CSS class, but all I'll know is that it contains 'IN' or 'OUT'.
So something like this:
if ($(jRow).hasClass('IN-*')){
jRow.attr( "class", "OUT-foo" );
}else{
jRow.attr( "class", "IN-foo");
}
Does anyone have any helpful ideas?
search
is the appropriate method here. However, your approach will work fine in this case, so long as the matched string continues to evaluate to true. – Catiline