The O shortcut


#1



https://www.codecademy.com/courses/web-beginner-en-4hxyb/0/7?content_from=make-an-interactive-website%3Ajquery-events#


On the commented line. why doesn't the code work when this is used instead of '.current'?


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

@saykul.90,
If you use

        $(document).keypress(function(event){
              if(event.which === 111)
            {
                $('.current').children('.description').toggle();  
            }
       
        });

and you want to use the "o" key
you will have to put the document on-focus
by clicking in the =green= area


#3

I did not understand. I was saying why doesn't the $(this).children('.description').toggle(); work as it did on line no 7?


#4

@saykul.90,
With $(document) the this will point to the whole HTML-Document


#5

Got it now. Thank you for the help Leonard !


#6

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