Why do I need to call the document body for keydown event?


#1

For 8. The keydown() event

It gives this example:

$(document).ready(function() {
  $(document).event(function() {
    $('div').effect(anim, duration);
  });
});

Why do we need to call the document body for an event? We weren't doing this for mouse clicks, why would need to do it for keyboard clicks?


#2

You dont have to bind events to $(document). You can bind the event directly to the target element.$(document) targets the entire html document. it is ideal when
you want bind a common handler for several elements that requires same functionality. In this exercise you don't have a huge DOM tree so $(document) should suffice. Read more on
_event delegation and propagation_