To disable a button in jQuery or any other html element you have to add disabled attribute in particular element.
In below example if you check the chekbox then button will disable, means you will not able to click the button and if you un-check the checkbox then button will be become clickable.
$('.btnClick').attr('disabled', 'disabled');// can not click
$('.btnClick').removeAttr('disabled');// able to click
CODE
<!DOCTYPE html> <html> <head> <title>jQuery With Example</title> <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('.btnClick').click(function () { alert("Welcome to Here"); }); $('.chkDisable').click(function () { if ($(this).is(':checked')) { $(this).parent().find('.btnClick').attr('disabled', 'disabled'); } else { $(this).parent().find('.btnClick').removeAttr('disabled'); } }); }); </script> </head> <body> <div class="Container"> <button type="button" class="btnClick">Click</button><br /> <input type="checkbox" class="chkDisable" /> Please click this checkbox to disable the button. </div> </body> </html>
DISPLAY
Please click this checkbox to disable the button.
No comments :
Please Give Your Feedback