How to change the default for a show/hide div

How can I change this script so that the default is set to display rather than hide?

<script type="text/javascript">
 function showhide(id) {
var e = document.getElementById(id);
e.style.display = (e.style.display == 'block') ? 'none' : 'block';
 }
</script>

The page I’m working on is

I want the information for the first clickable section to show when the page loads.

What does your CSS tell the hidden element to do when it’s initially loaded?

Not sure. What am I looking for on the CSS file?

Probably the class name of the hidden content.

this code comes right after the script. Is this it?

<div id="CK71" style="display:none;">

That looks like what you’d need. Is that class only used on that one block of content? If so, as a test, try taking the style="display:none;" piece out. It should make the text visible, what I’m not quite sure of, it how is will affect the behaviour of the JS itself.

Well, the hidden text does show up. However, the columns I had setup on the page are completely skewed and there doesn’t seem to be a way to hide the text again.

Hmm… well you know why it’s not visible at least. Hiding it again should be a case of getting the JS to toggle the setting - I know there’s a built in jQuery function for that, but I’d not resort to that unless you’re loading it anyway.

The column thing is slightly puzzling, as I can’t think that class would be used elsewhere. We may need more erudite heads on the case.

I got it! That was the right line, I just changed “display:none;” to “display:block;”

Thanks for your help!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.