Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM (Retiring) Responding to User Interaction Listening for Events with addEventListener()

Why not CSS?

I'm just wondering if this specific solution to a problem (to capitalize the letters on hover) was just for practice and understanding or is it common to actually use JavaScript for for this?

Because all I had to do in CSS was to write: li:hover { text-transform: uppercase; }

to get the exact same effect, including with new list items. So if it actually is preferable to use JS for this, can someone tell me what the benefit is? Thanks in advance!

1 Answer

Steven Parker
Steven Parker
218,861 Points

Since you're taking a JavaScript course, I think it's safe to assume that most exercises will be primarily to illustrate how the mechanisms operate and not necessarily the best way to perform a specific function.

When possible, CSS-based solutions will often be more efficient and/or browser compatible than those using JavaScript. But there are also many things that can be done only using JavaScript.