.click() and .hover


#1

$(document).ready(function() {
$('div').click(function() {
$('div').hover(function() {
$(this).addClass('red');
});
});
});
The code is not working, HELPPPPFSDALHJFSDJHKFDSHKGGFUJKO


#2

Hi Floaguirre,

You need to separate these parts of your code, they shouldn't be nested inside each other:

$('div').hover(function() {
  // do stuff
});

and

$('div').click(function() {
  // do stuff
});

#3

Can you explain why?


#4

@littleyac They're different things, they should be left separate. Also, the hover() part won't trigger until you click on the <div>, which isn't how it's meant to work in this case.


#5

3 posts were split to a new topic: Exercise 6, why does it tell me to make sure I'm adding the "active" class on hover?


#8