I am working with a pretty old version (Chromium 25) of chromium. I would like to use tagName
to get the name of the used HTML tag. I know that Element.tagName
works for 43+ chromium versions, but is there an alternative that I can use for older versions?
Asked
Active
Viewed 282 times
0

Mr. Polywhirl
- 42,981
- 12
- 84
- 132

Nida
- 51
- 2
- 5
-
https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName . https://stackoverflow.com/questions/4878484/difference-between-tagname-and-nodename – intekhab Oct 01 '20 at 13:17
1 Answers
2
You would need nodeName
From tagName
doc
For Element objects, the value of tagName is the same as the value of the nodeName property the element object inherits from Node.
Below screenshoot is Browser compatibility for tagName
const el = document.getElementById('test')
console.log(el.tagName)
console.log(el.nodeName)
<span id="test">Example</span>

hgb123
- 13,869
- 3
- 20
- 38
-
You could use a pipe e.g. `const tagName = el.tagName | el.nodeName` to always get one or the other. Alternatively, you could create a shim or polyfill for `Element.tagName` to return the `nodeName`. – Mr. Polywhirl Oct 01 '20 at 13:20
-
@Mr.Polywhirl sure thing, thanks, separated log here is just for demonstration – hgb123 Oct 01 '20 at 13:22
-
@Mr.Polywhirl I assume you mean the logical OR rather than the bitwise OR? I don't believe the latter will give you anything sensible. – Ivar Oct 01 '20 at 13:27
-
1@Ivar You're right, my mistake... `const tagName = el.tagName || el.nodeName` – Mr. Polywhirl Oct 01 '20 at 13:28