Hide elements in Javascript

Posted on 26-04-2013 13:38 by graham
This tutorial shows how to hide HTML elements using pure Javascript or JQuery.

Pure Javascript code


To hide an element using pure Javascript, we need to modify the elements CSS style
document.getElementById("elementId").style.visibility = "hidden";

To display the element again, set the visibility property to visible:
document.getElementById("elementId").style.visibility = "visible";


JQuery code


To show and hide an element in JQuery, do:
// hide it
$("#elementId").hide();

// show it
$("#elementId").show();
Comments

 

Add comment

Has this tutorial been helpful to you? Or do you see anything wrong? We appreciate your opinion!
Your comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
Email:
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems