JavaScript JavaScript and the DOM 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
203,226 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.