I am curious if it is possible to get tag equivalent to jquery's $('tag_name') by just having an id at hand? For example:
var some_id = document.getElementById('my_Id');
//and then do something like
var get_tag = some_id.its_tag;
Is something like this possible?
I know we can get all tags into one place, like list, and then loop through that list and check each id, but curious if there is something that can be done elegantly?
Thanks!
Alternative is known, but would be great if original question actually has some answer too.
var some_id = document.getElementById('my_Id');
//and then do something like
var get_tag = some_id.its_tag;
var some_id = document.getElementById('my_Id');
var tag = some_id.tagName;
You can use the Element.tagName property (it represents the tag name in uppercase):
var some_element = document.getElementById('my_Id');
console.log(some_element.tagName); // => P
<p id="my_Id">Hello</p>
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