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>.
How do I get an element or element list by it’s tag name. Take
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 wantArray.from(document.querySelectorAll('a')). Maybe polyfillArray.from()if your browser does not support it yet. I can recommend https://polyfill.io/v2/docs/ very much (not affiliated in any way)