How to change the visibility of a <div> tag using javascript in the same page?
Though asked not to be done with jquery, but can be done as: $('.my_div_tag_id').css('visibility','hidden');
<div id="contentDiv">
This is the content .
</div>
if you want to change the visibility of div with id="contentDiv" using javascript then you can do with..
var eleDiv = document.getElementById("contentDiv");
// based on condition you can change visibility
if(eleDiv.style.display == "block") {
eleDiv.style.display = "none";
}
else {
eleDiv .style.display = "block";
}
Hope this code helps you........
Using the visibility
attribute:
Show the div with id="yourID"
:
document.getElementById("yourID").style.visibility = "visible";
To hide it:
document.getElementById("main").style.visibility = "hidden";
Using the display
attribute:
Show:
document.getElementById("yourID").style.display= "block";
Hide:
document.getElementById("yourID").style.display= "none";