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

Boonsuen Oh
Boonsuen Oh
18,788 Points

JS/jQuery question

Are they literally the same and there's no any bad or good between them except the code length?

First

$('h1').mouseover(function() {
  $(this).css("color","red")
}).mouseleave(function() {
  $(this).css("color","blue")
});

Second

$('h1').mouseover(function() {
  $(this).css("color","red")
});
$('h1').mouseleave(function() {
  $(this).css("color","blue")
});

1 Answer

Kallil Belmonte
Kallil Belmonte
35,561 Points

Yes, both work, there's also this version that works exactly the same:

Third

$('h1').mouseover(function() {
  $(this).css("color","red");

  $(this).mouseleave(function() {
    $(this).css("color","blue");
  })
});
Boonsuen Oh
Boonsuen Oh
18,788 Points

Thank you for providing the extra solution. I appreciate it.