Whirlwind990
Whirlwind990

Reputation: 99

Storing data in a HTML element that won't display on view

Just wondering if its possible to store invisible data in a HTML tag that activates the element but doesn't show data.

For instance, if I had a <h1></h1> element and I wanted the element to be active so the DOM would think there was a real header there and therefore include any additional properties (ie padding, margins etc) is it possible to have the element active by putting in something between that tags that wont display on the view? I remember seeing something ages ago that did this but can't remember where from...

Upvotes: 0

Views: 777

Answers (1)

zedfoxus
zedfoxus

Reputation: 37129

You can use visibility: hidden CSS like so:

<h1 style="visibility:hidden">...</h1>

Check out https://developer.mozilla.org/en-US/docs/Web/CSS/visibility for information about visibility.

EDIT:

In order to hide the contents of the heading, you could use JavaScript or a library like jQuery. Let's take jQuery for example. You could do something like this: https://jsfiddle.net/yanpbw1v/. In this example, I am saving h1's data into a variable and then clearing h1's data out.

Upvotes: 2

Related Questions