<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);
});
})
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.