If for the sake of argument I'm applying a class to a <p> and an <a> and I then want to determine whether it was an <a> or a <p> that was clicked, is there a way to do it?
Example of intended use:
$(".selector").click(function(){ element = $(this).whatElementWasClicked(); // return "a" or "p"
} 4 Answers
Use something like this:
$(".selector").click(function(event){ var element = event.target.nodeName } 0 $(this).is("a") , for example, will also work. This is useful if you're checking against a more complicated selector, not just a particular element type.
use tagName for getting the tag