0

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?

3
  • Do you mean all tags on the page, or all tag names that are considered valid HTML? Mozilla has a good reference: developer.mozilla.org/en-US/docs/Web/HTML/Element Commented Nov 2, 2015 at 20:04
  • all tag names that are considered valid HTML. I did also mean if its possible offline, without connection Commented Nov 2, 2015 at 20:11
  • Alright - the link I gave should give a complete list. There might be some HTML specs in the future for custom tag types, though. Commented Nov 2, 2015 at 20:12

3 Answers 3

1

if you want all tags this should do:

document.querySelectorAll("*");

if you want html child tags :

document.querySelector("html").children;
Sign up to request clarification or add additional context in comments.

2 Comments

getElementsByTagName may be faster vs querySelectorAll
I did mean if its possible to get all existing tags in HTML Language, not on the page.
0

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'));

6 Comments

i don't wanna get tags of the page, i wanna get all elements that exists in html language.
Why would you want to do that? Just give an explanation.
Aah my bad. You could have been a bit more specific in your question, tough. I will leave this answer here, just in case anyone is looking to achieve this.
@aCodingN00b just need to know, sometimes i don't have connection and i was wondering if its possible.
If you're just doing it for yourself, you're better off just downloading a list or something.
|
0

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?

3 Comments

That's not what i mean. I wanna get all existing and valid(that i can use it) tags in HTML Language, not on the page. The aim is for example if i dont have internet connection and wanna learn some html in the meantime, but i can't access online docs, and I didn't download any.
You could open the Developer Tools in Chrome and look at everything in the DOM. You can even execute javascript on the console and manipulate them or edit them directly. On Macs it is shortcut alt+cmd+I. Or look through the menu.
And if you want it offline try a book. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.