How would I generate a list of distinct HTML tags in a page using JavaScript (must work in IE6)

后端 未结 4 701
轮回少年
轮回少年 2021-01-28 10:53

The end result I\'m after is a JavaScript array containing a list of tag names that are used in the HTML document eg:

div, span, section, h1, h2, p, etc...

I wan

4条回答
  •  长发绾君心
    2021-01-28 11:41

    What you're looking for is document.all.tagName At the top of my head, a for loop like this should do it (providing that you're gonna filter the tags you don't want on that list)

    for(i = 0; i < document.all.length; i++)
    {
      console.log(document.all[i].tagName);
    }
    

提交回复
热议问题