Si la clase no está presente en la tabla 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.

preguntado el 10 de marzo de 12 a las 15:03

anywhere in table or cell,and where's the class applied to? -

Only remove .redText if .ui-icon-triangle-1-s does not exist at all in the table. -

@santa: Isn't that what esta respuesta ¿lo hace? -

I think a few answers on this page are correct -- the problem is with my code, I am afraid. I have another function that manipulates the classes. I don't get the class .redText removed until that function has run. I think I need to run additional check after all that's done. -

Then execute the code after your first function is done .You can use something like .promise().done(function() { your funtion here }); -

3 Respuestas

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

respondido 10 mar '12, 15:03

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.

respondido 10 mar '12, 15:03

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");
}

respondido 10 mar '12, 15:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.