javascript - Get element type using id or class - Stack Overflow

admin2025-04-20  0

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.

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.

Share Improve this question asked Dec 13, 2015 at 2:22 ZomoXYZZomoXYZ 1,8811 gold badge22 silver badges47 bronze badges 3
  • 1 google./… – user1106925 Commented Dec 13, 2015 at 2: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 Commented Dec 13, 2015 at 2: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. – user1106925 Commented Dec 13, 2015 at 2:46
Add a ment  | 

1 Answer 1

Reset to default 6

Access the tagName property.

With JavaScript:

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

With jQuery:

$('#elementID').prop('tagName');
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745115072a285813.html

最新回复(0)