Cherry
Cherry

Reputation: 675

Calling the tr attribute via Jquery and find my inner check box

I have "tr" element with attribute "data-uid". How can I call that "data-uid" in my jquery for finding my checkbox to add the disabled class.

Here is my code :

<tr data-uid="994f164a-5778-49ee-b05e-abb74bbf9b93" role="row">
   <td role="gridcell"><label class="row-select-wrapper">
      <input type="checkbox" class="row-select"><em></em></label>
   </td>
   <td role="gridcell">test</td>
   <td role="gridcell"></td>
   <td role="gridcell"></td>
</tr>

I tried something like this

$('data-uid[994f164a-5778-49ee-b05e-abb74bbf9b93]')
.find('<input type="checkbox"').attr("disabled", "true");

Upvotes: 2

Views: 156

Answers (2)

Rion Williams
Rion Williams

Reputation: 76557

You actually need to enclose the type of attribute selector that you are using in square braces as well when using attribute selectors:

$('[data-uid="994f164a-5778-49ee-b05e-abb74bbf9b93"]').find('<input type="checkbox"')
                                                      .attr("disabled", "true");

Additionally, you could simplify your selector if you wanted to target checkboxes beneath your <tr> by using the :checkbox pseudoselector:

// This will disable all checkboxes beneath the specified row
$('[data-uid="994f164a-5778-49ee-b05e-abb74bbf9b93"] :checkbox').prop('disabled',true);

Upvotes: 2

Nico_
Nico_

Reputation: 1386

You were close :

 $('[data-uid=994f164a-5778-49ee-b05e-abb74bbf9b93]')
          .find('input[type=checkbox]').attr("disabled", "true");

Upvotes: 2

Related Questions