3

Is there a way to get the element type using an id or class with JQuery?

With the HTML as <div id="elementID"></div>, using JQuery I want to return div.

ZomoXYZ
  • 1,763
  • 21
  • 44
  • 1
    https://www.google.com/search?q=site%3Astackoverflow.com+javascript+get+tag+name&ie=utf-8&oe=utf-8 –  Dec 13 '15 at 02:27
  • 1
    @squint I looked it up on Google, I couldn't find a thing. I wonder why it didn't show up in my search or in the `Questions that may already have your answer` section when writing my question. – ZomoXYZ Dec 13 '15 at 02:29
  • 1
    No problem. I just like to show people the search I used to find answers. Figure it'll help next time. Using the `site:` search feature helps quite a bit. –  Dec 13 '15 at 02:46

1 Answers1

5

Access the tagName property.

With JavaScript:

document.getElementById('elementID').tagName;
// or
document.querySelector('.elementClass').tagName;

With jQuery:

$('#elementID').prop('tagName');
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
  • 2
    Note `.tagName` returns "DIV". Either use `.toLowerCase()` or use `.localName` instead. – Andy Dec 13 '15 at 02:30