1

I have a jQuery selection, is there a way to determine what type of element it is (e.g. <a>,<span>,etc...)?

palswim
  • 11,856
  • 6
  • 53
  • 77
aepheus
  • 7,827
  • 7
  • 36
  • 51

2 Answers2

3

You can use .is() with a selector to see it it matches, like this:

var is_span = $(this).is("span");

Or if you have a DOM element:

var is_span = this.tagName == "SPAN";
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
1
$("#elementId").get(0).tagName
Matt Asbury
  • 5,644
  • 2
  • 21
  • 29