How do I get an element or element list by it's tag name. Take for example that I want all elements from <h1></h1>
.
document.getElementsByTagName('a') returns an array. Look here for more information: http://web.archive.org/web/20120511135043/https://developer.mozilla.org/en/DOM/element.getElementsByTagName
Amendment: If you want a real array, you should use something like Array.from(document.getElementsByTagName('a'))
, or these days you'd probably want Array.from(document.querySelectorAll('a'))
. Maybe polyfill Array.from()
if your browser does not support it yet. I can recommend https://polyfill.io/v2/docs/ very much (not affiliated in any way)