Enable disable HTML table element with JQuery in disabled <TR>

V.B picture V.B · Sep 11, 2014 · Viewed 14.5k times · Source

I am creating a dynamic HTML table with JQuery. Sample code is below.

var tbody=$("#myTable tbody");

var tableRow;

if(somevariableIsTrue)
   tableRow=$("<tr>").attr("disabled",true);
else
   tableRow=$("<tr>");

var td=$("<td>");
    td.appendTo(tableRow);

var tdn=#("<td>");
tdn.appendTo(tableRow);

 tableRow.appendTo(tbody);

now I create different TDs and append to the tableRow. If the disabled attribute of the row is TRUE obviously all the TDs for that row will be disabled too. But I want that my first TD of disabled row shouldn NOT be disabled as its a checkbox column on its click I want to enable/disable the same row. I tried different ways to get the checkbox in the first column and tried to enable it but all fails. Can some one suggest me how to do this in JQuery

EDIT Hope this screen shot helps to understand my requirement enter image description here

as seen in the image first row is disabled including the first td with checkbox. I want to checkbox column to be enabled all the time so that on checking it the row becomes enabled and un checking leaves the row disabled again.

Answer

Rich picture Rich · Sep 15, 2014

You could just call

$('input[type=checkbox]').removeAttr('disabled');

or

$('input[type=checkbox]').prop('disabled', false);

on all your checkboxes. This would essentially re-enable all of your checkboxes