Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable/enable all elements in div [duplicate]

Tags:

html

jquery

How to make quick disabling/enabling of all the elements in any div (inputs, links and jQ Buttons)?

like image 514
Sergey Metlov Avatar asked Aug 05 '11 19:08

Sergey Metlov


People also ask

How do I enable and disable a div?

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.

How do I make a div inactive in HTML?

A simple way to disable any DIV including its contents is to just disable mouse interaction.

How do I stop div clicking?

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.


2 Answers

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/

like image 162
karim79 Avatar answered Sep 30 '22 15:09

karim79


$('#my_div').find('*').prop('disabled',true);

To re-enable, simply use .removeProp() http://api.jquery.com/removeProp/

like image 27
AlienWebguy Avatar answered Sep 30 '22 15:09

AlienWebguy