Is it simple enough to go inline, can you show me?
Main Topics
Browse All TopicsIs it possible to create a collapsible div using CSS only? I know you can do this with Javascript, but I am curious if there is some way of simulating an asynchronous show/hide action on-click. What I want to do is on-click show or hide a div, similar to how a CSS drop-down menu will show/hide a list item on-hover. So, is there a way to do it on-click with CSS without reloading the page? I don't know of any pseudo-classes that will allow this.
Finally, will the solution be IE6/IE7 compatible?
Thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I haven't written it yet, but it is going to be a simple list. not sure if either of these are right.
<div class="hide"><li><a class="show" href="#">Item 1</a></li></div>
<div class="hide"><li><a class="show" href="#">Item 2</a></li></div>
<div class="hide"><li><a class="show" href="#">Item 3</a></li></div>
<div class="hide"><li><a class="show" href="#">Item 4</a></li></div>
or
<li class="hide"><a class="show" href="#">Item 1</a></li>
<li class="hide"><a class="show" href="#">Item 2</a></li>
<li class="hide"><a class="show" href="#">Item 3</a></li>
<li class="hide"><a class="show" href="#">Item 4</a></li>
Basically, I want the list item, on click, to expand to show more detailed information below that list item:
<li class="show"><a class="show" href="#">Item 1</a><br />
Expanded Info Expanded Info Expanded Info Expanded Info</li>
<li class="hide"><a class="show" href="#">Item 2</a></li>
<li class="hide"><a class="show" href="#">Item 3</a></li>
<li class="hide"><a class="show" href="#">Item 4</a></li>
Below is some sample code. Keep in mind, that it would be better to NOT declare javascript inline like this but since you mentioned it, I figured I would put it in like that. Also, if you are using any kind of javascript framework this task would be much easier as there are built in functions in almost all the frameworks I have worked with for speeding up the hiding/showing of elements and for selecting them through the DOM as well.
Note, that while I used a method of getting the parent element of the link, and then selecting the p element from inside the parent, you could also select the next element, or change the p to a span/div/whatever (you would need to change "...getElementsByTagName('
Also, all you are doing here is swapping out a class on the p inside the li element. You will need to write the styles for that depending on how you are styling your page. If you want something more simple you could change out the last line of the javascript function to:
el.style.display = el.style.display == 'none' ? 'block' : 'none';
if you wanted to just toggle the display portion of the styles and didn't care about other styles on the element.
Anyway, there are a number of ways of doing it, as you can see; but I would recommend trying out a javascript framework for this type of thing if you are going to use css effects often since they have a lot of neat built-in functions for doing stuff like this. JQuery, Mootools, and Prototype are the three main products I have used (they are all free). I personally prefer mootools as it's animation effects are pretty powerful, but they are all great tools for mixing standards html coding with the power of javascript and css.
Business Accounts
Answer for Membership
by: ritetekPosted on 2009-02-22 at 12:57:45ID: 23706431
As far as I know there is no pseudo-class for click in CSS, however you could write two classes, and use very simple javascript to swap out the classes for the "hide" and "show" states.