I'm working on a simple javascript code.
Based on the condition I should change the visibility of the tag from hidden to visible.
I should use javascript alone. No jQuery or AJAX. Any idea or suggestion please.
Another way to make a div visible or invisible is with the display property. Then we can make it visible with: const div = document. querySelector('div') div.
The document. getElementById will select the div with given id. The style. display = "none" will make it disappear when clicked on div.
The hidden attribute hides the <div> element. You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <div> element is not visible, but it maintains its position on the page.
visibility
attribute:Show the div with id="yourID"
:
document.getElementById("yourID").style.visibility = "visible";
To hide it:
document.getElementById("main").style.visibility = "hidden";
display
attribute:Show:
document.getElementById("yourID").style.display= "block";
Hide:
document.getElementById("yourID").style.display= "none";
<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........
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