Kiki
6
Q:

how to hide an element in html

// javascript
<script>
	document.getElementById("id").style.display = "none";  //hide
	document.getElementById("id").style.display = "block"; //show
	document.getElementById("id").style.display = ""; 	   //show
</script>

// html
<html>
	<div id="id" style="display:none">
    <div id="id" style="display:block">
</html>

// jquery
<script>
	$("#id").hide();      
	$("#id").show();
</script>
4
.classname {
    visibility: hidden;
}
6
/*Hiding an element can be done by setting the display property to none. 
The element will be hidden, and the page will be displayed as if the element is not there:
Example:
*/

h1.hidden {
  display: none;
}

/*visibility:hidden; also hides an element.
However, the element will still take up the same space as before. 
The element will be hidden, but still affect the layout:
Example:
*/

h1.hidden {
  visibility: hidden;
}
2

 
  <p hidden>This paragraph should be hidden.</p>
 
 
2
var link = document.getElementById('nav-ask');
link.style.display = 'none'; //or
link.style.visibility = 'hidden';
2
<div id="main"> 
  <p> Hide/show this div </p>
</div>

('#main').hide(); //to hide

// 2nd way, by injecting css using jquery
$("#main").css("display", "none");
1

New to Communities?

Join the community