Right now, i have a div and i did an inline style, display:none. When the user click a button, it will call a javascript function and change the div display to according value. However, how can i do such check as they kept returning display:none even when in actual, display is block. Here is my javascript code
function unhideDiv(){
var divDOC=document.querySelector('divContent');
var result = document.getComputedStyle(divDOC, '').display;
if(result=='none'){
divDOC.style.display="block";
}
else
{
divDOC.style.display="none";
}
}
Here is my html code
<div id="divContent" style="display:none;" >
</div>
<button onclick="unhideDiv()">Click This </button>
Your help will be much appreciated. Thanks in advance!
.toggle(). If you want to do this yourself, use a variable to store the state. In your function, switch the variable, then set the style based on its new value.querySelector('divContent')should bequerySelector('#divContent')but since you have jQuery tagged in this question why not just usetoggle()...?Element.style.displayto what you want to begin with, you won't have to get a computed style. Or think 0 and 1.window.getComputedStyle()rather thandocument.getComputedStyle()jsfiddle.net/r4t1b7ub