1

If we only know the ID of an element, is it possible to check using javascript or jQuery what kind of an element it is, whether its textarea, div, span or something else?

gbd
  • 213
  • 1
  • 11
  • the answer should be here: [http://stackoverflow.com/questions/10539419/javascript-get-elements-tag] – Peter Fischaleck Aug 12 '15 at 09:08
  • 1
    possible duplicate of [How can javascript determine the type of an html element?](http://stackoverflow.com/questions/254302/how-can-javascript-determine-the-type-of-an-html-element) – akalikin Aug 12 '15 at 09:08
  • Is this meant for a third-party library, an extension or something? For a custom piece of JavaScript that belongs to a page, formally you are supposed to already know what element it is. That's what IDs are for: to positively identify an element. So when you don't know what it is, there's something fundamentally wrong with our design! – Mr Lister Aug 12 '15 at 09:13

2 Answers2

7

By using jQuery:

$("#someid").prop("tagName");

By using JavaScript:

document.getElementById("someid").tagName;
Srinu Chinka
  • 1,471
  • 13
  • 19
1
document.querySelector('#id').nodeName
Bogdan Kuštan
  • 5,427
  • 1
  • 21
  • 30