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 JavaScript and the DOM (Retiring) Responding to User Interaction Listening for Events with addEventListener()

Aakash Srivastav
seal-mask
.a{fill-rule:evenodd;}techdegree
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Points

Listening for events with addEventListener()

This is my third question related to this video.
Now my question is , why doesn't he used the "style" property to make the letter uppercase, as he did in the other videos.
As he said , in order to change the css of any elements we use "style" property.
In this case it will go like this:

for( let i = 0 ; i < listItems.length ; i+=1){
    listItems[i].addEventListener( 'mouseover' , () => {

        listItems[i].style.textTransform = "uppercase";     // used "style" property      

    });
    listItems[i].addEventListener( 'mouseout' , () => {

        listItems[i].style.textTransform= "uppercase";  // used "style property     
    });
}

Is there any specific reason that he didn't used this method?

1 Answer

Daniel Hernandez
Daniel Hernandez
13,437 Points

I believe he used a different convention just to teach different ways of doing the same thing. I don't personally know the advantages over one method from the other, so I expect it is just a difference in method.