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

后端 未结 4 662
轮回少年
轮回少年 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:28

    Get all tagnames in the document, unique, crossbrowser, plain js:

    var els = document.getElementsByTagName('*'), tags = [], tmp = {}
    for (var i=0;i

    use

    if (!(els[i].tagName in tmp) 
         && !/head/i.test(els[i].parentNode.tagName) 
         && !/html|head/i.test(els[i].tagName))
    

    to exclude the

提交回复
热议问题