Download sliding show/hide script

Demo | Demo 2

Bookmark and Share

Put this into your <HEAD> section

Put this into your <BODY> section


Create content

You use plain HTML to create your "questions" and "answers". This is coded in the following format:
<div class="dhtmlgoodies_question">Q: What kind of site is ?</div>
<div class="dhtmlgoodies_answer">
  <div> is a private site developed and maintained by Alf Magne Kalleland.

Notice that I have used two DIVs for the answers.

You use CSS(The part between <style type="text/css"> and </style>) to configure the layout. Look at the examples for more help.

I have used a background image in this demo for the rounded edge at the right of each question:

If you like to use it, right click on it and select "Save target As". Put the file in a sub folder called "images".

Initialize show content

You can automatically expand content when the pages load. This is done by calling the showHideContent function manually. Example:

<script type="text/javascript">
showHideContent(false,1); // Automatically expand first item

This will automatically show the first item.

Javascript variables

There are two javascript variables which you can use to control the slide speed. These are:
var dhtmlgoodies_slideSpeed = 10; // Higher value = faster
var dhtmlgoodies_timer = 10; // Lower value = faster

If you want to be able to expand multiple items at the same time, you can do that by setting dhtmlgoodies_expandMultiple to true, example:

var dhtmlgoodies_expandMultiple = true;

Update log

  • September, 11th, 2006: Fixed problem with the script in Netscape 7.1.
  • April, 3rd, 2006: Fixed problem with initial sliding in IE.


Admin comment
You can do almost everything with css, but I think you need some javascript.

Here's one simple example:

<style type="text/css">
.expandedNode div{
display: block;
.collapsedNode div{
<div class="collapsedNode" style="cursor:pointer" href="#" onclick="this.className = this.className=='collapsedNode' ? 'expandedNode' : 'collapsedNode'">Main node
<div>Content to expand<br>Content to expand</div>
<div class="collapsedNode" style="cursor:pointer" href="#" onclick="this.className = this.className=='collapsedNode' ? 'expandedNode' : 'collapsedNode'">Another Main node
<div>More Content to expand<br>More Content to expand</div>

The only Javascript here is use to toggle css class

DHTMLGoodies at 04:33PM, 2011/02/17.
I am having a problem with this code - I'm sure it's me.I'm trying to implement this example (as is) into my Blogger site. If you're not familiar with the concept (I wasn't..but I'm also not a programmer anymore), it handles things like this:1. The Site template contains the header section for every page.2. Each page contains just the pages (aka the post's) content - there are no header/title sections available for each page. So, what I did was this:- I copied and pasted the first bit of code entitled "PUT THIS INTO THE SECTION" into the site template just before the end tag. I made no modes to the code.- When I went to update that code (save it), it informed me that there was a problem with the following message: "Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.XML error message: The entity name must immediately follow the '&' in the entity reference."- Now, in the meantime, I've put the second code snippet into the page itself (aka the post), but obviously, I can't test it until I get the code working properly.Any ideas?
House at 05:50PM, 2011/02/25.
the css javascript code is amazing, it's magic, thank you
Mayssa at 01:19AM, 2011/03/08.
Hello! anyone knows how to create read more in html. I have that site I need to update. I'd like to be able to introduce the subject of some news and then add a read more link, alowwing the user to read the following text, but on the same page!

I figured I could use javasccript document write on a link but it does not seem to work, Anyone has the key?
Nao at 05:47PM, 2011/03/08.
I cannot manage to automatically show some tabs on loading the page.Where exactly do I place the following code?showHideContent(false,1); // Automatically expand first item
Nout at 08:43PM, 2011/03/11.
Help please - the 'initialize show content' code does not seem to work. I want to have my first answer expanded when loading the page, but when I add the code it breaks and nothing expands or collapses.
Tyler at 07:38PM, 2011/03/12.
Outstanding post!! Works perfect, I did make some css mods.
bryan at 08:37PM, 2011/03/15.
I LOVE this script!
mort at 11:35AM, 2011/03/30.
Axel G.
Hi there... I have a problem here, this script is awesome!!I'm trying to use it in a gallery whith 3 pictures for each row ("dhtmlgoodies_question" divs) and a bunch of rows. when you click one of the pictures it slides another div with some information of the picture ("dhtmlgoodies_answer"). the problem is when I click on a picture it slides the div, but also the other pictures from the row, except on the last item of the row, it slides fine.What I'm looking for is when I click on a picture from the row, the "answer" div slide only the bottom rows and not the other divs in the same rowI hope you can give me a hint on how to solve this I really need to finish my project soonThanks!
Axel G. at 08:54PM, 2011/04/02.
Sreekumar MP
Good work. I was writing java script for the code earlier. But you were managed the effect in just one line of code. Great.
Sreekumar MP at 06:40AM, 2011/04/07.
Thanks for the awesome script.Is it possible for it to show another html page instead? like glinding in a new page into a content frame?
Clement at 11:52PM, 2011/04/13.
I love this code,Actually, I am looking of this.
Newbie at 09:54AM, 2011/04/15.
Great script and html. But - I still have a number (>10%) of my users who still use IE7 as their primary browser. And the sliding doesn't always work with IE7. All other versions and browsers work great. Any ideas as to how to modify the script to make it compatible? Or is the answer to create a separate IE7-only style sheet? Thanks!
alf at 03:39PM, 2011/04/22.
I was able to answer my own question after playing around with the style sheet a bit. I ended up changing the answer_content padding to 5px, which cleared up the IE7 issue. I also added padding-bottom:25px to answer_content because FF4 was cutting off sections when printing (but not in the display).
alf at 10:13PM, 2011/04/22.
I was wondering if it was possible to put a submenu with the content
mike at 09:02PM, 2011/04/28.
Thanks for sharing this. simple, elegant, works beautifully
Melissa at 10:06PM, 2011/04/28.
guioo diesel
I tried to use on tumblr, but the blockpost moves with the list when these slidemy tumblrtheme is this, if you can help me
guioo diesel at 01:18AM, 2011/04/29.
This is great, but I also need to use this to show the first 4 lines of text, then a "more.." link that will expand the div to show all the content. Is there a way to do this? I have searched high and low for this, but can't seem to find a suitable solution.Thanks
Hans at 05:18AM, 2011/04/30.
Great effect! I am having trouble mimicking the "two column" look in the DEMO 2 example. How do you get the div layers to be side by side like that, instead of the way that they are in DEMO 1?Thanks!
artemishunter at 10:10PM, 2011/05/10.
I have some problen in IE7 when I insert the code in a div with "overflow-y:auto"es.:
leonardo.g at 05:02AM, 2011/05/18.
could anyone tell me how to make sure the first div is default open?
redzuan at 07:29AM, 2011/05/19.
HeyI want to do the same thing but with a navigation bar. My main goal is to click a nav link, display the content then click another nav link and then display that content but hide the previous. How on earth do i do this???
Rizwan at 08:16PM, 2011/05/31.
awesome! thanks for sharing.
simo at 12:49AM, 2011/06/02.
Hi! This is really great stuff and I'm going to use it in my site. I was just wondering if you could help me out on one point? Is it possible to get a hover effect (colour change) on mouse over for the question links? Please help if you can.Dom
Dom at 02:49PM, 2011/06/05.
@dom:u can insert a hover effect by adding some css in the example:html code:*Your Question Link*similar css code:p.slider-link{ color:#666; margin:0px; padding:0px; }p.slider-link:hover { text-decoration:underline; color:#F00;}hope this helps...btw: awesome script m8
n8wandler at 09:40AM, 2011/06/09.
sry, here my html code :) LINKNAME sry for doubleposting...
n8wandler at 09:41AM, 2011/06/09.
damn, the guestbook kills my html-code :Dgive the answer only a "" -tag with a special class, for example "slider-link" and design this with css like my post above, dont forget the hover element!peace
n8wandler at 09:47AM, 2011/06/09.
very nice idea!
Can i use this slide menu verticaly?
If i can,please help me. I don't know javascript but expert in php:D
soroush at 07:01PM, 2011/06/17.
can we implement this script for image sliding up and the hiden content coming on click
ANI at 02:41AM, 2011/06/18.

Doesn't work :-(
MyNameIs at 02:45PM, 2011/06/19.
Admin comment
showHideContent(false,1); works in the demo.It's important that you have that line near the end of your page. Example: on the line above , especially if you have a lot of <table> tags on your page.
DHTMLGoodies at 11:05AM, 2011/06/20.
Tennar Sanal Hayat Teknolojisi
i tried to use this on my page but i couldnt success
Tennar Sanal Hayat Teknolojisi at 11:49AM, 2011/06/20.
Admin comment
Tennar,I cannot find that you are using this script on that page.
DHTMLGoodies at 03:49PM, 2011/06/20.
Hi, I need to be able to change the text inside dhtmlgoodies_question on click - how do I do this? Sorry new to javacript! Thanks
LP at 01:07AM, 2011/07/21.
Hi,i would like to know, what I should change to have a inside-slide in a slide. My Problem is, that the height of the slide don't change if I touch the inside-slide.Do you have a quick answer for me?Thank you very much!
Lennart at 08:16PM, 2011/07/22.
Hi! Thanx for this script. Is great!I have a question: I don´t want to show the first item or any item. I want to see every one hidden at first. How can I do that? I tried this:showHideContent(false,0);but the script stops working.thanks!
Segio at 06:59PM, 2011/08/02.
Hey, thanks for the amazing script.Wondered if you could kindly help solve my problem. I have a link within my question div to an external page. So when the link is clicked the answer box starts to slide down just before the page changes.How can i fix this?Thanks, Daryl
Daryl at 01:39PM, 2011/08/03.
Hey Daryl,Thank you for this code! I'm trying to incorporate it into a Tumblr page, but it seems that when I create an HTML blog entry it automatically converts DIV tags to P. Can this code work or be adapted by using P class="dhtmlgoodies_question" instead of DIV?Thanks in advance for any insight on this! :)Cheers,Dominic
Dominic at 05:24PM, 2011/08/10.
Hi, I love the script. It works perfectly. But I have a question.. " is there anyway to change the color of those blue boxes.. say to dark red or something?"My website is black,Maroon & Gold and I was hoping to change the color to something similar to that.. The BLUE looks nice and all it just doesn't match my website color scheme. Any advice is helpful. Thanks. PS. I'm not too familiar with all this I use Dream weaver to edit most things..
LadyFuzzy at 11:05AM, 2011/08/11.
The code:<script type="text/javascript">showHideContent(false,1);</script>Doesn't work on me. It stops the whole script.But the code:<script type="text/javascript">initShowHideDivs();showHideContent(false,1);</script>Does work. But, whenever a page loads, it opens the content but then it closes again after the page loads 100%. Do you know what is causing to happen?Please email me if needed. I really need this to be fixed as soon as possible. Thank you for your great script.
kaspr at 06:30AM, 2011/08/17.
Very Nice Script.. i used this script in my blog..Click here to increase the sliding speed
sureash at 06:41AM, 2011/08/27.
Requiem Inori
So I have been using this code for a long time now, and I always loved how it worked! Recently, though, I have tried working on a project where another area is using this code (albeit with different widths and setup) for an affiliate section. The first area that I used the original code in was for our sliding content on the left side area of the site, which was perfect for hiding cluttering information like news or introductory (it is an area which uses 250pixels in width). The second area was going to be the affiliate area,which uses 699 pixels in width) and so I had to copy the first code into another location, rename the title areas so that they were not the same as the ones in the first code in hopes that it would not cause a conflicting issue between them.However, a confliction still occurred. The area with the affiliates slides, but the area with the side navigation no longer slides. Apparently you cannot have two versions of the code on the same page, even if the parts are renamed and the width designated is different.I have worked really hard trying to figure out how to fix this and have come up with no answers. I want to keep the first area the same, since it is fine, but I want to try and get a simple content slider that works the same way for the second area that the affilate place is using.A friend and I have tried to just have the two areas use the same code setup, but because one area needs 250 pixels, and the other needs 699 pixels, in width... the outcome is either that one area is cut short, or the other area is spaced out.http://knightoffate.proboards.comThe two places using it are listed below.Left side navigational areas: Introductory Synopsis, News areas, Soundtrack area.Affiliate Box: Affiliate box and content.I posted this up in the proboard area as well, colour coding the areas for better view.
Requiem Inori at 11:51PM, 2011/10/06.
luis gustavo
if I want to use FADE + SLIDE, how should I do?
luis gustavo at 05:24AM, 2011/11/25.
Hi, I think this is a great script and it works well on my site. I do have one question I hope I can get help with. I have it setup so when some one clicks on "Read More..." the divs expand and show my content. When you click on "Read More..." again it shrinks the divs. My question is where and how can do I insert code so when you click "Read More..." the box expands and the "Read More..." changes to "Read Less...". And when you click on "Read Less..." the divs collapse and "Read Less" changes to "Read More...".Hopefully this is understandable. Thanks in advance for you help.
Whichrtmej at 10:00PM, 2011/11/27.
Hello, thank you for this script. I like to make a change on the script but I can not do it.I put a background image in the class. DivQuestion and I would put another background image when the user hovers over the block divQuestion and also when the block is open. Vou can sm'aider please. Thank you in advance.
Nicolas at 10:11AM, 2011/12/22.
Hi, I am trying to incorporate this script into my site. I have added all the script to the Head section and this is what I have for the body.<body><div id="Readmore" class="dhtmlgoodies_readMore">Read More...</div><div class="dhtmlgoodies_extension"> <div> <p> And a whole bunch of text.... </p> </div> </div></body>When I run the code and I click on "Read More" my text expands and when I click on "Read More" again my text retracts. Everything is working as it should.What I want is to change "Read More" to "Read Less" when it is clicked and my text expands and change "Read Less" back to "Read More" when my text retracts.Any help would be appreciated.Thanks Whichrmejt
whichrtmej at 05:21AM, 2012/01/08.
Ryley Wade
Try as I might I cannot seem to get this working in any version of IE. If anyone can suggest something I would really appreciate it. The slide function just doesn't want to work.
Ryley Wade at 12:42AM, 2012/01/15.
Gasten Sauzande
How can i transfer this code to a button? I am starting at javascript so u'll need to explain with details. Thanks.
Gasten Sauzande at 03:55AM, 2012/01/18.
this javascript works decent in firefox although i'm having major issues integrating it into my website of works in FF, fails to work in chrome and IE. can someone help me out here?
chuck at 04:20AM, 2012/01/21.
I have a question.. how do I modify the answere height for each question. Thank you! It works perfect!
jack at 10:42PM, 2012/02/17.
It works in chrome...thank you so much....
engonge at 11:25AM, 2012/02/27.
Is there a way to link to them from another page, so that the question you linked to is open when the page gets opened.Cheers
Alex at 04:10PM, 2012/02/29.
Hello, it's wonderful script and many thanks for it, BUT, when I have let's say 4 200x200px divs hidden and slide them down, when I click on another one, page's scrolling bar is set to the top ... can I avoid that "bug" please?
Giovanni at 08:03PM, 2012/03/12.
I don't want the active slide to close when I click on it. How do I solve that?
Carl at 09:51AM, 2012/04/03.
hey hi, i just want to ask that what shud i do if i want to close or hide the answer div on click outside the question div also.. please help me
meena at 10:23AM, 2012/05/31.
iframes!I have tried this code and am having fun with it.However, when in an iframe and looking at a long 'answer' div then clicking on a 'queston' div with a much shorter answer, the parent page does not scroll back up and you are looking at empty space (unless you sroll back up manually).Any way to fix this so it will scroll automatically? ie, it needs a second, 'scroll to top' function, for the showhide onclick event or something similar.
tony at 06:10AM, 2012/07/04.
Being able to click in the 'answer' div to close it would also be great.
tony at 11:12AM, 2012/07/04.
Great Code. No complaints. How about making it fading in/out simultaneously with sliding out/in? Any ideas?
Igor at 11:40PM, 2012/08/31.
Thanks . this is very useful.
sibghatullah at 07:46AM, 2012/09/03.
Hello, I was looking for a Show/Hide text script. yesterday all day I searched and tried some of them but nothing worked until I saw your simple code. I am just a simple html user, don't know anything about script writing etc. Anyway I tried your below example and it is perfectly worked and I really like it. Thanks for sharing with us, My only concern is I need FADE EFFECT with toggle, any idea?<style type="text/css"> .expandedNode div{ display: block; margin-left:20px; } .collapsedNode div{ display:none; } </style> <div class="collapsedNode" style="cursor:pointer" href="#" onclick="this.className = this.className=='collapsedNode' ? 'expandedNode' : 'collapsedNode'">Main node <div>Content to expand<br>Content to expand</div> </div> <div class="collapsedNode" style="cursor:pointer" href="#" onclick="this.className = this.className=='collapsedNode' ? 'expandedNode' : 'collapsedNode'">Another Main node <div>More Content to expand<br>More Content to expand</div> </div>
Mey at 11:01AM, 2012/09/11.
anyway I used your main code and it worked very well as well and using fade effect too.. great work. thanks
Mey at 02:13PM, 2012/09/11.
Jon Mustafa
Thanks for this script. It works brilliantly, one thing I do wish to change though, and that is the questions and answers spacing, at the moment they is 0 point spacing betwen each question/answer. How can I make the spacing more for each question/answer?Again many thanks for a great scriptJon Mustafa
Jon Mustafa at 07:35PM, 2012/09/27.
This is an excellent code! Thanks so much!
Brandon at 02:27AM, 2013/10/20.
Hello,I want to ask this:1.My questions are are not in english but in greek. Whay shoyld I change so that I can see them before put it on browser. In the browser it work fine but before that it shows me strange letters. I'm not a programmer.. Please some help2. Where should I put the <script type="text/javascript">showHideContent(false,1);</script>3.How can I put a background foto for the answers.Thank you .
elly at 02:33PM, 2014/05/20.
GREAT SCRIPT!!! :-)BUTshowHideContent(false,1);STILL DOESNT WORK even put at the end of the pageCheck for answering
Carlo at 01:14PM, 2015/03/26.
I am so happy I found this code. Thank you very much.I'd love to use this on a multi-level vertical Wordpress navigation. Is it possible to use this with child and parent elements instead of two independent divs?If you have any tips on how to modify this script so that it can work with multi-level vertical menus I would greatly appreciate it.Thank you
victoria at 10:55PM, 2015/06/02.

Post your comment

Don't have an avatar? Create one at

Confirmation code:

Go to

About/Contact | A good idea? | Submit a script | Privacy notice
© 2005 - 2024