Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hide a section of HTML without removing it?

I want to hide a section of HTML, and stop it being viewable from the webpage itself without removing it. Is this possible in HTML or CSS, or can anyone recommend a Javascript library capable of doing this? The part that needs hiding looks similar to this:

<p>text1<strong>text2</strong></p>

I don't want it to display on the website but I do want it viewable when looking at the code directly.

Any ideas?

like image 359
Peter David Carter Avatar asked Oct 24 '15 04:10

Peter David Carter


People also ask

How do I hide a particular section in HTML?

To hide an element, set the style display property to “none”. document.

Can you hide HTML elements?

Completely hiding elements can be done in 3 ways: via the CSS property display , e.g. display: none; via the CSS property visibility , e.g. visibility: hidden; via the HTML5 attribute hidden , e.g. <span hidden>

How can I hide HTML element without using space?

The following style rule hides an element on a web page: display: none; When you set the value of display to none, the affected element will disappear. This means the element will no longer take up any space on the web page.

How do I hide HTML code from inspect element?

You simply can't. Code inspectors are designed for debugging HTML and JavaScript. They do so by showing the live DOM object of the web page. That means it reveals HTML code of everything you see on the page, even if they're generated by JavaScript.


4 Answers

Add a "hidden" class to select the target HTML and use display: none in CSS:

HTML:

<p class="hidden">text1<strong>text2</strong></p>

CSS:

.hidden {
  display: none;
}

...or you could inline it directly:

<p style="display:none">text1<strong>text2</strong></p>
like image 103
Chris Camaratta Avatar answered Oct 08 '22 14:10

Chris Camaratta


You can use css display:none

<p style="display: none;">text1<strong>text2</strong></p>
like image 29
NessBird Avatar answered Oct 08 '22 13:10

NessBird


There's a visibility property in CSS: http://www.w3schools.com/cssref/pr_class_visibility.asp

You could wrap whatever elements you want hidden in a <div> and set it's visibility to hidden. This property can also be changed dynamically with Javascript.

You could also look into using jQuery, which has animated hide() and show() functions

like image 2
Tim Sanch. Avatar answered Oct 08 '22 15:10

Tim Sanch.


I'm not sure what exactly you need, but you can try commenting it out, like:

 <!--<p>text1<strong>text2</strong></p>-->

Or, add a class/id then select it and on css:

.myhidden{
display: none;
}
<p class="myhidden">text1<strong>text2</strong></p>
like image 2
zhack Avatar answered Oct 08 '22 14:10

zhack