Enable disable HTML table element with jQuery <TR> disabled

I am creating a dynamic HTML table with jQuery. Sample code 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 add to tableRow. If the disabled attribute of the string is TRUE, obviously all TDs for this string will also be disabled. But I want my first TD of the disconnected row not to be disconnected as its check column column when clicked. I want to enable / disable the same line. I tried different ways to check the box in the first column and tried to enable it, but all failed. Can someone tell me how to do this in jQuery

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

as can be seen on the first line of the image, it is turned off, including the first td with a flag. I want the checkbox column to be on all the time, so when checking, the line becomes on and not checking that the line is off again.

+5
source share
2 answers

Here is a simple solution:

 // first row checkboxes $('tr td:first-child input[type="checkbox"]').click( function() { //enable/disable all except checkboxes, based on the row is checked or not $(this).closest('tr').find(":input:not(:first)").attr('disabled', !this.checked); }); 

See how it works in JSFiddle

+2
source

You can just call

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

or

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

on all of your flags. This essentially will re-enable all of your checkboxes.

0
source

Source: https://habr.com/ru/post/1202323/


All Articles