Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Create an Accordion Menu with CSS

Vilius Grižas
Vilius Grižas
2,753 Points

Accordion. CSS or Java Script?

In the beggining of the video the he mentioned, that it's more usual to do this in Java Script. I still have no knowledge of that language, but just got curious. Dear programers, who know a lot of languages! :) If you'd get a task to do an Accordeon like this. Would you do it in CSS or Java Script? And why? :)

Allison Hanna
Allison Hanna
36,222 Points

Just to clarify, you are asking about JavaScript, not Java. Java != JavaScript. Java is to JavaScript as Car is to Carpet. Important distinction. :)

Vilius Grižas
Vilius Grižas
2,753 Points

Oh yeah, my bad. I put the wrong name. I know about the difference although I didn't worked with them. The mistake is only in the title..

Still, Javascript is one word. Jesus!

1 Answer

It is possible to make an accordion with either only CSS or only JavaScript, but you'll probably get the best results using a combination of the two. Generally you'll use JavaScript (JS) to handle user interaction, and change classes on the elements, and have CSS style them based on those classes.

And the problem with doing it only using CSS3 would be cross browser support, you have less chances to deal with different browser issues using JavaScript or even better jquery