Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery select attribute != includes elements that don't have the attribute

Tags:

jquery

I am trying to select elements that do not match a given attribute id. Based on the following simplified example, why does $("td[groupId != 1]") return elements that do not even have the groupId attribute? Is there another way to select elements that have a groupId where the value is not 1?

<table border="1">
<tr>
    <td>Group 1</td>
    <td groupId="1">1 - 1</td>
    <td groupId="1">1 - 2</td>
    <td groupId="1">1 - 3</td>
    <td>2</td>
    <td groupId="2">2 - 1</td>
    <td>3</td>
    <td groupId="3">3 - 1</td>
    <td>Total</td>
</tr>
<tr>
    <td>1</td>
    <td groupId="1">1</td>
    <td groupId="1">1</td>
    <td groupId="1">1</td>
    <td>2</td>
    <td groupId="2">2</td>
    <td>3</td>
    <td groupId="3">3</td>
    <td>0</td>
</tr>
<tr>
    <td>1</td>
    <td groupId="1">1</td>
    <td groupId="1">1</td>
    <td groupId="1">1</td>
    <td>2</td>
    <td groupId="2">2</td>
    <td>3</td>
    <td groupId="3">3</td>
    <td>0</td>
</tr>
</table>
like image 282
tessa Avatar asked Jul 05 '26 04:07

tessa


1 Answers

Try:

$("td[groupId][groupId!='1']")

This type of selector matches all elements with the attribute groupId, but then only chooses the ones where the value is not 1.

like image 123
John Rasch Avatar answered Jul 07 '26 18:07

John Rasch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!