button disable test

by hiteshbhilai2010

HTML

<table id = "mytable" border="1">
<tr>
<td><button class = "btn" id = "click1">button1</button></td>
<td><button class = "btn" id = "click2">button2</button></td>
</tr>
<tr>
<td><button class = "btn" id = "click3">button3</button></td>
 </tr>
</table>

<button class = "btn1" id = "click4">Add row</button>

<button class = "btn3" id = "click5">disable all button</button>
<button class = "btn3" id = "click6">enable all button</button>

JavaScript

//for <button> tags --> pls uncomment below line 
 // $(":button").attr("disabled", "disabled");


$(":button").click(function(){
//alert(this.id);
})

$(".btn1").click(function(){
$("#mytable").append("<tr><td>"+'<button class = "btn" >new button</buttton>'+"</td></tr>");
})

//Even your code works !!!! ---> uncomment below lines to see


jQuery('body').on("click", "#click5", function() {
      $(".btn").each(function () {
       $(this).attr("disabled", true);
    });
})

jQuery('body').on("click", "#click6", function() {
      $(".btn").each(function () {
       $(this).attr("disabled", false);
    });
})