Giorgos Giorgos - 3 months ago 12
jQuery Question

diasable buttons in a table with the same class

I have an html page with jquery that contains a table with buttons in a column as following. I need to disable all buttons with class

Crem
.

I have try the following but not working.

$(document).ready(function() {
$( ".Crem" ).prop( "disabled", true);
}

<table id="settlementsd" class="table table-striped">
<thead>
</thead>
<tbody>
<tr>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th><button type="submit" id="stlmtdadd" class="Crem btn btn-sm btn-info" ><span class="glyphicon glyphicon-plus-sign"></span> </button></th>
</tr>
<tr>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th><button type="submit" id="stlmtdadd" class="Crem btn btn-sm btn-info" ><span class="glyphicon glyphicon-plus-sign"></span> </button></th>
</tr>
<tr>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th><button type="submit" id="stlmtdadd" class="Cadd btn btn-sm btn-info" ><span class="glyphicon glyphicon-plus-sign"></span> </button></th>
</tr>

</tbody>
<tfoot>
</tfoot>
</table>

Answer

Buttons are simple to disable as disabled is a button property which is handled by the browser:

<button class="btn" disabled>My Button</button>

To disable these with a custom jQuery function, you'd simply make:

p.s You are missing brackets and semicolon at the end of function

  $(document).ready(function() {
     $(".Crem").prop('disabled',true);
  });

Here is a working jsfiddle

Comments