7. The O Shortcut issue with code


#1



7. The O Shortcut


I'm getting this error message and I don't know what to fix...I've read other posts and I can't seem to find my issue...I am 'toggling the article inside the event handler', or at least I think I am. Help please.

"Oops, try again. It looks like the o key isn't opening a description. Remember to toggle the current article's description inside the event handler. Look back at the instructions for the code."


var main = function() {
    $('.article').click( function () {
        $('.article').removeClass('current');
        $('.description').hide();
        
        $(this).addClass('current');
        $(this).children('.description').show();
        
        $(document).keypress(function(event) {
            if(event.which === 111) {
                $('current').children('.description').toggle();
        };
    });
});
}
$(document).ready(main);


#2

HI your $(document).keypress(function(event) {..}); shouldn't be inside the $('.article').click( function () {..}); so your code it should look like that

var main = function() { #open the main function
   $('.article').click( function () { #open the click function .article
      ...
   } #close the click function .article
   
   $(document).keypress(function(event) { #open the keypress
      ...
   }); #close the keypress
} #close the main function

$(document).ready(main);

#3

Ok I managed to get it to work, thank you.

Also, I have a question regarding the 'current' class.
Why in the Add and Remove Class is it just 'current' and not '.current'. That's what I have to type to get it to work on the website. Is that an error or is there a real difference?

Cheers.
Simon


#4

It's because when you use the .current with the dot you select the class and when you use the current without the dot it's the name of the class.so the

.removeClass()
.addClass()

takes as paramter the name of the class.
you can find find more about it here
https://api.jquery.com/addClass/
https://api.jquery.com/removeClass/


#5

hi,
i had the same problem but mine still doesn't work


#6

Hi you should create a new topic with your code and the link of the lesson.


#7

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