By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,249 Members | 1,853 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,249 IT Pros & Developers. It's quick & easy.

Show/Hide Content on Clicking Link

Ajm113
100+
P: 161
Ok I googled and searched this site, but is their a way I can create a drop down content so if a user clicks on a link content will appear on the bottom and when the user clicks the link again the content would hide.

Any code?
Aug 9 '07 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
Put your content in a div and set the visibility to "hidden". For the link, call a function which checks the visibility and reverses it (hide if visible and show if hidden).
[HTML]<a href="#" onclick="showHideContent(); return false;">Show/Hide Content</a>
<div id="content" style="visibility: hidden">content appears here</div>[/HTML]
Expand|Select|Wrap|Line Numbers
  1. function showHideContent () {
  2.  var content = document.getElementById("content");
  3.  if (content.style.visibility == "hidden") content.style.visibility = "visible";
  4.  else content.style.visibility = "hidden";
  5. }
If you need to actually add and remove content from the page, use the display property instead.
Aug 9 '07 #2

Ajm113
100+
P: 161
Thanks, now I just need to add cookie control on here and I got it!
Aug 9 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Thanks, now I just need to add cookie control on here and I got it!
Glad you got it working (well, it wasn't too hard, was it?)

PS. Changed thread title.
Aug 10 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.