Reputation: 17
I'm wondering if its possible to get all existing html tags(body, head, div, ul etc.) with javascript. By all existing i dont mean all on the page, but all valid. Is there a function that does that?
Also if there isn't - Is it somewhere in Firefox or Chrome files?
Upvotes: 0
Views: 729
Reputation: 251
Different approach not accessing the DOM, since I'm still not sure what the aim is: Take the document as a string and look for "<"and ">" with a regular expression? Shall I elaborate on that?
Upvotes: 0
Reputation: 1812
You could write a function that retrieves all the child elements of the <html>
element. This would allow you to get all of the html elements on the page.
function getAllChildElements (start) {
var children = start.childNodes;
var elements = children;
for (var i = 0; i < children.length; i++) {
elements.concat(getAllChildElements(children[i]);
}
return elements;
}
var all_elements = getAllChildElements(document.querySelector('html'));
Upvotes: 0
Reputation: 8354
if you want all tags this should do:
document.querySelectorAll("*");
if you want html child tags :
document.querySelector("html").children;
Upvotes: 1