Combining click and hover.JQuery events Nr.4


#1

https://www.codecademy.com/courses/web-beginner-en-JwhI1/0/4?curriculum_id=50a3fad8c7a770b5fd0007a1#

I know that there is a post about this event already and there is a code that should work but i tried that code and it did not work.Tried to write it with 'this' instead of 'div' does not work.I'm stuck and could use some help.Thanks :slight_smile:
Error it shows is "Oops, try again. Please follow the instructions on the Full Preview page to test your code".Circle turns red and when i click on it it fades so code works.


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

});


#3

probably forgot the $ sign in the beginning of the document.

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

#4

Uppss, my mistake.I have the $ signin the beginning of the document just accidently didn't copy it.It still doesn't let me to the next exercise.Still the same error.Can't get it.


#5

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

you had to add the hover and class before the click function and close it accordingly. Took me a while to figure it out. Good Luck!


#6

Thanks a lot for a reply :slight_smile:
Got ir!


#7

That's annoying. The instructions specifically state "Below your .click() event code from the previous lesson, create a new selector $('div')"

Thanks for your help!


#8

I made it work with this:

$(document).ready(function() {

$('div').click(function() {
    $(this).fadeOut('fast');

    });

 $('div').hover(function() {
    $(this).addClass('red');
    });

});


#9

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