/    Sign up×
Community /Pin to ProfileBookmark

Simple Div – Show / Hide

Hi,

I have a div called content and an image

[code]<a href=”#”><img src=”click_me.gif” /></a>

<div id=”content”>
<p>stuff in here…</p>
</div>[/code]

When I click on the image I want the content to hide and then another click to show.

Simple but after reading examples on here I can’t get it to work.

Any help would be much appreciated

Thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@semi-sentientSep 14.2006 — Put the following in the head of your document:
<i>
</i>&lt;script language="javascript" type="text/javascript"&gt;
function toggleElement(id) {
var objEl = document.getElementById(id).style;
objEl.visibility = (objEl.visibility == "hidden") ? "visible" : "hidden";
}
&lt;/script&gt;


Then add the following to your image (removing the <a> tags that wrap it):
<i>
</i>&lt;img src="click_me.gif" onclick="toggleElement('content')" /&gt;


[b]Edit:[/b] I added a parameter and changed the name so that you could use this for any element and not just the content DIV.
Copy linkTweet thisAlerts:
@semi-sentientSep 14.2006 — Edit: ooops, posted in wrong thread....
×

Success!

Help @Disfunctional spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...