4 Combining .click() and .hover()


#1

Hi!
in this session I added like this and it worked.

$(document).ready(function(){
$('div').click(function(){
    $(this).fadeOut('fast');
});
$('div').hover(function(){
  $(this).addClass('red');
});
});

but I'm wondering why I can't use .css (" background-color:red"); insted of .addClass?

Please give me advice!
Thank you !


#2

The style sheet already has a defined class, .red that sets the background when the class attribute is added to the element. We can add and remove the class dynamically and the page updates each time.


#3

Make sense! I didn't notice it has already defined.
Thank you !!


#5

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.