JQuery - finding the element $ (this)

Possible duplicate:
Can jQuery specify a tag name?

Hello!

This question is so basic that I am ashamed to ask, but I tried to find the answer within 30 minutes without any results.

How to find out which item was clicked in the code below.

$('*').click(function (event) { var this_element = $(this).???; return false; }) 

I am looking for the this_element variable to be set to 'a' if it is a link, 'p' if it is a paragraph 'div' if ...

Thanks!

+7
jquery elementname
source share
2 answers

Try the following:

 $('*').click(function (event) { var this_element = this.tagName.toLowerCase(); return false; }); 

The this pointer refers to the actual element it is affecting. As part of the DOM Level 2 kernel, all DOM elements have the .tagName property.

+8
source share
 $(this).get(0).tagName; 
+3
source share

All Articles