0

I have the following

$("tr[data-id]:not([data-id='" + id + "'])")

that gets all the rows in the table except the one I want to exclude based on id value, but I now need to also exclude those where the checkbox is disabled, but I cant figure out how to incorporate the additional parameter into the selector statement.

Below is an example of a row that should be excluded ..... based on its checkbox disabled attr

<tr data-id="5">            
    <td>
        <label style="position:relative">
            <input class="active status-color checkbox-slider yesno " title="no" type="checkbox" disabled="disabled">
            <span class="text"></span>
        </label>
    </td>
</tr>

Thanks.

I need rows that DO NOT match the id variable AND of those rows DO NOT contain a checkbox that IS disabled

user3071434
  • 133
  • 1
  • 2
  • 13
  • Current CSS implementations afaik do not support a parent selector. So you wont be able to select the row directly by its content. you will have to select the checkbox first and the use some thing like `closest( 'tr' )` to get the table row. – Sirko Feb 14 '16 at 16:20
  • Maybe you help this answer: [Selecting element by data attribute](http://stackoverflow.com/a/2487751/5925490) – Yauheni Pakala Feb 14 '16 at 16:22

2 Answers2

2

You made me crazy... https://jsfiddle.net/VixedS/em1cjuas/

$("tr[data-id!="+id+"]:not(:has('input[type=checkbox]:disabled'))")
Vixed
  • 3,429
  • 5
  • 37
  • 68
  • Sorry if I was unclear ... I'm looking to select all the rows; except ones with a matching ID; and ones that contain a disalbed checkbox – user3071434 Feb 14 '16 at 16:59
  • ok but what if the element with the matching ID has a disalbed checkbox? Include or not in the selector? – Vixed Feb 14 '16 at 17:02
  • can you please check it https://jsfiddle.net/VixedS/615xjrqy I'm getting lost in your explanation... – Vixed Feb 14 '16 at 17:15
  • Element with the matching ID will never be disabled. All that I need is rows that DO NOT match the id variable AND of those matching rows DO NOT contain a checkbox that IS disabled – user3071434 Feb 14 '16 at 17:18
  • So you are looking to select all the rows, except ones with a matching ID, and except the ones that contain a disalbed checkbox??? – Vixed Feb 14 '16 at 17:21
1

Use has & :enabled like following.

$('tr[data-id]:not([data-id="' + id + '"]):has(":checkbox:enabled")')

Or you can use filter like following.

$('tr[data-id]:not([data-id="' + id + '"])').filter(function () {
    return $(this).find(':checkbox:disabled').length == 0;
});
Ibrahim Khan
  • 20,616
  • 7
  • 42
  • 55