Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable & Disable a Div and its elements in Javascript [duplicate]

I am looking for a method to Enable and Disable the div id="dcalc" and Its children.

<div id="dcalc" class="nerkheArz"  style="left: 50px; top: 150px; width: 380px; height: 370px;  background: #CDF; text-align: center" >  <div class="nerkh-Arz"></div>  <div id="calc"> </div> </div> 

I want to Disable them at loading the page and then by a click i can enable them ?

This is what i have tried

document.getElementById("dcalc").disabled = true; 
like image 597
Emax Avatar asked Dec 07 '11 22:12

Emax


People also ask

Whats does enable mean?

Definition of enable transitive verb. 1a : to provide with the means or opportunity training that enables people to earn a living. b : to make possible, practical, or easy a deal that would enable passage of a new law. c : to cause to operate software that enables the keyboard.

Does enable mean allow?

The usual distinction between allow and enable is that allow means "to not prohibit something, to let it happen, to remove any constraint that would prevent something from happening" and enable means "to make something possible".

Does enable means on or off?

In simple terms: Enable = To turn On. Disable = To Turn Off. When you turn on a feature you enable it. When you turn a feature off you disable it.


2 Answers

You should be able to set these via the attr() or prop() functions in jQuery as shown below:

jQuery (< 1.7):

// This will disable just the div $("#dcacl").attr('disabled','disabled'); 

or

// This will disable everything contained in the div $("#dcacl").children().attr("disabled","disabled"); 

jQuery (>= 1.7):

// This will disable just the div $("#dcacl").prop('disabled',true); 

or

// This will disable everything contained in the div $("#dcacl").children().prop('disabled',true); 

or

//  disable ALL descendants of the DIV $("#dcacl *").prop('disabled',true); 

Javascript:

// This will disable just the div document.getElementById("dcalc").disabled = true; 

or

// This will disable all the children of the div var nodes = document.getElementById("dcalc").getElementsByTagName('*'); for(var i = 0; i < nodes.length; i++){      nodes[i].disabled = true; } 
like image 121
Rion Williams Avatar answered Sep 22 '22 13:09

Rion Williams


If you want to disable all the div's controls, you can try adding a transparent div on the div to disable, you gonna make it unclickable, also use fadeTo to create a disable appearance.

try this.

$('#DisableDiv').fadeTo('slow',.6); $('#DisableDiv').append('<div style="position: absolute;top:0;left:0;width: 100%;height:100%;z-index:2;opacity:0.4;filter: alpha(opacity = 50)"></div>'); 
like image 32
Sergio Ramirez Avatar answered Sep 25 '22 13:09

Sergio Ramirez