I want to write something like this in javascript:
var all_headings = document.getElementsByTagName("h1,h2,h3,h4,h5,h6");
all_headings would then be a list of all elements that are h1 or h2 or h3... And in the order that they appear in the document, of course.
all_headings
h1
h2
h3
How do I do it?
With modern browsers you can do
document.querySelectorAll("h1, h2, h3, h4, h5, h6")
Or you could get cross-browser compatibility by using jQuery:
$("h1, h2, h3, h4, h5, h6")
1.4m articles
1.4m replys
5 comments
57.0k users