Home > Javascript > How to get which element clicked

How to get which element clicked


We can find out which element clicked on web document.
First we need to create a function i.e
function gotElement(){
var ele = arguments[0] || window.event, origEl = ev.target || ev.srcElement;
alert(ele.tagName);//Getting  tag name of element.
}

Now call this function like this…
document.onclick = gotElement();

Whenever user click on click on document then a alert will open that contains tag name.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: