so suppose I call document.getElementsByName("title");
in javascript
and I want to know the type of the tag of the element that is returned by that function, for instance, to see if it's a meta tag or a div tag or a span tag, etc
how would I go about doing this?
document.getElementsByName("title");
returns a set of elements not a single element
so within a cycle you could use element.tagName
to get the tag
basicly
document.getElementsByName("title")[0].tagName
should work
You have returned a NodeList
object, so you would need to be more specific with your selector, or choose the first element using an index of 0, as in the other answers.
Whilst you can use nodeName
or tagName
, nodeName
is the better option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With