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 Callback Functions in JavaScript Callbacks and the DOM Using Callbacks on Text Inputs

Tashan Duncan
.a{fill-rule:evenodd;}techdegree seal-36
Tashan Duncan
Front End Web Development Techdegree Graduate 17,774 Points

Why not just use CSS :Focus pseudo-class??

I see the Styles.css file in the workspace has a highlight class with the below properties:

.highlight {
    box-shadow: 0px 0px 10px #755d00;

I moved the properties onto the focus class and got the same result as the video without having to use event listeners.

input[type="password"]:focus {
  background: #fff;
   box-shadow: 0px 0px 10px #755d00; //here

Why even use an event listener for something like this? arent we using more code than is needed?

Thank you

1 Answer

Sheila Anguiano
Sheila Anguiano
Full Stack JavaScript Techdegree Student 26,968 Points

Well, like most problems, there is always more than one solution, in this case the objective of the exercise is to show how to use callbacks with Event Listeners with something simple like highlighting a field on a form, but for example CSS won't help you if you want to click on an item and delete it from a TO DO list for example (or maybe it could, but I don't think it would be the best way)