7. The o shortcut


#1

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

When I click on the articles. they open, however, I can't find anything wrong with my code. Keep getting this error:

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);

What am I missing? Thoroughly stumped on this one.


#2

Okay. I figured it out, I was missing the period ('.current').

Okay, I have another question that is a bit more complex.

I am having a hard time understanding WHAT exactly this code is doing.

So we begin with

var main = function() {     
 $('.article').click(function() {          <---this basically hides the article right?---->
       $('.article').removeClass('current');
       $('.description').hide();

 $(this).addClass('current');                     <--- why is this used? this would mean article right?---->
       $(this).children('.description').show();        <---- this opens it up, a counter to hiding the article and it's description?---->
   });

 $(document).keypress(function(event) {       <!---I understand this one--->
       if(event.which === 111) {
           $('current').children('.description').toggle();
       }
   });
   
}

#3

@ethereal92 Going through your comments in order,

  1. No. That only listens for clicks on HTML elements with the article class. The hiding happens in the two lines directly below that one.
  2. Yes, this refers to the current object, which is the article in this case.
  3. That line does open up the description. I'm not sure what you mean by this part, though:

a counter to hiding the article


#4

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