Javascript catching mouse click event and know what DOM element is being clicked

Asking some great encoders in irc.freenode at #javascript channel, people are having an extensive help to me.
I got this code working, but here I use the mootools JS Library but still the same as native javascript syntax.

$(document).addEvent('click', function(e){
console.info(e.target.get('id'));
});


// This works in IE
$(document).attachEvent('onclick', function(e){
alert(e.srcElement.id) // gives the id of the element being clicked
});

Through it, it does prints or gives me the id of the element being clicked. It's really cool knowing this technique.


Comments

Popular posts from this blog

Using Oracle 11g thru VirtualBox appliance in Mac OS X Lion

LVM: How to remove a volume using pvremove

Use Shell Editor for Eclipse for editing bash, ksh, csh in Unix/Linux system