Home › Forums › JavaScript › $(document).on() vs $('#id').on() › Reply To: $(document).on() vs $('#id').on()
April 8, 2014 at 10:31 pm
#167867
dyr
Participant
In the first case you’re attaching the event listener to the document, which listens for an event originating from an element with a particular id that bubbles up the DOM.
In the second case, you’re attaching the event listener to the element itself.
Go here: https://api.jquery.com/on/ and read the section with the heading “Direct and delegated events.”
Cheers :)