JQuery disable multiple input div children

I want to do something like below from the checkbox,

Each line has a check box, and I want to disable all input fields in the line with the .room class when I click on the button.

function toggleStatus(link) { $(link).closest(".room").children(':input').attr('disabled', true); } 

also tried

 function toggleStatus(link) { $(link).closest(".room").children('input[type=text]').attr('disabled', true); } 
+4
source share
1 answer

Your question has some ambiguities, so the following may not be exactly what you are looking for.

After clicking, you must go to the nearest row in the table, find all the inputs that have the class name .room , and set their disabled attribute in accordance with the state of the flag itself.

 $(":checkbox").click(function(){ $(this).closest("tr").find(":input.room") .attr("disabled", $(this).is(":checked")); }); 

This assumes a structure similar to the following:

 <table> <tbody> <tr> <td><input type="checkbox" /></td> <td><input type="text" class="room" /></td> <td><input type="text" class="room" /></td> <td><input type="text" class="room" /></td> </tr> <tr> <td><input type="checkbox" /></td> <td><input type="text" class="room" /></td> <td><input type="text" class="room" /></td> <td><input type="text" class="room" /></td> </tr> </tbody> </table> 

Online Demo: http://jsbin.com/umimu/edit

+6
source

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


All Articles