How to make quick disabling/enabling of all the elements in any div (inputs, links and jQ Buttons)?
Using jQuery The idea is to disable click events inside div with jQuery and CSS. This can be done by setting pointer-events CSS property with the help of jQuery's . addClass() function.
A simple way to disable any DIV including its contents is to just disable mouse interaction.
To disable clicking inside a div with CSS or JavaScript, we can set the pointer-events CSS property to none . Also, we can add a click event listener to the div and then call event. preventDefault inside.
Links do not have a "disabled" property, so you'll have to work a bit harder.
$('#my_div').find(':input').prop('disabled', true);
$('#my_div a').click(function(e) {
e.preventDefault();
});
To re-activate:
$('#my_div').find(':input').prop('disabled', false);
$('#my_div a').unbind("click");
The :input
selector Selects all input, textarea, select and button elements.
Also see http://api.jquery.com/event.preventDefault/
$('#my_div').find('*').prop('disabled',true);
To re-enable, simply use .removeProp()
http://api.jquery.com/removeProp/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With