• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

how do i make my tag appear closed?

i have a button that hides and shows text.... but i cant figure out how to make it so it hides the text before hand?
function initialise() {
var element = document.getElementById('element-id');
if (element && element.style)
element.style.display = 'none';
function toggleDisplay(element) {
var style;
if (typeof element == 'string')
element = document.getElementById(element);
if (element && (style = element.style))
style.display = (style.display == 'none') ? '' : 'none';
if (!document.getElementById)
document.getElementById = function() {return null;};
<body onload="initialise();">
<!-- ... -->
<div id="element-id">Content to be hidden.</div>
<input type="button" value="Toggle content" onclick="toggleDisplay('element-id');">
<!-- ... -->

Open in new window

1 Solution
You can change your code this way in order for your text to be initially invisible.

Kind regards,

Matthias Vance
<div id="element-id" style="display: none;">Content to be hidden.</div>

Open in new window

runnerjpAuthor Commented:
thankyou worked perfectly
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now