4/12 What have i done wrong


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

it fades out but it doesn't turn red


#2

Hi

$('div').click(function(){ 
 // do something
}); // you didnt close on the right place

And hover means if you move your mousepointer out of the div red should be removed.
So $(this)addClass('red'); is wrong


#3

Correct is:
$(document).ready(function() {
$("div").hover(function) {
$("div").addClass("red");
});
});


#4

this is when you are click on the div it will be effect

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

this would be hover event and effect on div
see I have remove the click of the function.
$(document).ready(function(){
$('div').hover(function(){
$(this).addClass('red');
$(this).fadeOut('fast');
});
});


#5

Danced around with this for a bit. Here is the code it accepted
$(document).ready(function(){
$("div").hover(function(){
$("div").addClass('red');
$("div").click(function(){
$("div").fadeOut('fast');
});
});
});


#6

@amatandika That works, but the .click() thing should be outside of the .hover() function.


#7

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

});

});


#8

Exactamente ese efecto de cambiarle el color con hover y luego desaparecerlo con click queria hacer, pero no lo programaba bien :sweat:, gracias me fuiste de mucha ayuda :blush: :ok_hand:


#10

that's good, yeah it's working