santa
santa

Reputation: 12512

If class is not present in table w/jQuery

I need to remove a class from any place withing a table if another class is not found inside a span that is residing inside that table.

Basically I need to do the opposite of hasClass but I'm not sure what I'm doing wrong. Here's my code:

if ($("#nyTable").find("span").not("ui-icon-triangle-1-s")) {
    $("#nyTable").find("td").removeClass("redText");
}

<table>
<tr>
    <td>as</td>
    <td>asd</td>
    <td>werwe</td>
</tr>
<tr>
    <td><span class="ui-icon-triangle-1-s">asd</span></td>
    <td><span class="ui-icon-triangle-1-s">asd</span></td>
    <td><span class="ui-icon-triangle-1-s">asd</span></td>
</tr>
</table>

UPDATE: I need to make sure that this class .ui-icon-triangle-1-s does not exist anywhere in the table.

Upvotes: 1

Views: 110

Answers (3)

user1106925
user1106925

Reputation:

if (!$("#nyTable span.ui-icon-triangle-1-s").length) {
    $("#nyTable td.redText").removeClass("redText");
}

Upvotes: 1

Steven
Steven

Reputation: 19425

What about somthing like this?

//$('#nyTable span:not('ui-icon-triangle-1-s')').removeclass('redText');

$('#nyTable span').not('ui-icon-triangle-1-s').removeclass('redText');

This is just "pseudocode" - this exact code will probably not work, but try something along these lines.

Upvotes: 1

JREAM
JREAM

Reputation: 5931

Try it this way, you forgot your . for the class

if ($("#nyTable").find("span:not(.ui-icon-triangle-1-s)")) {
    $("#nyTable").find("td").removeClass("redText");
}

Upvotes: -1

Related Questions