Simple javascript to mimic jQuery behaviour of using this in events handlers

Posted by Marco Demaio on Stack Overflow See other posts from Stack Overflow or by Marco Demaio
Published on 2010-04-13T16:18:56Z Indexed on 2010/04/13 17:03 UTC
Read the original article Hit count: 465

This is not a question about jQuery, but about how jQuery implements such a behaviour.

In jQuery you can do this:

$('#some_link_id').click(function() 
{
   alert(this.tagName); //displays 'A'
})

could someone explain in general terms (no need you to write code) how do they obtain to pass the event's caller html elments (a link in this specific example) into the this keyword?

I obviously tried to look 1st in jQuery code, but I could not understand one line.

Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about javascript-events