Created
January 18, 2017 02:10
-
-
Save wangbinyq/2b6def9c39c1d246cb4fd2f60ea6c058 to your computer and use it in GitHub Desktop.
find how many html element have class or id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (() => { | |
| const $ = document.querySelectorAll.bind(document) | |
| const info = {} | |
| const total = [0, 0] | |
| $('*').forEach((el) => { | |
| const nodeName = el.nodeName | |
| const tagInfo = (info[nodeName] = info[nodeName] || [0, 0]) | |
| tagInfo[0] += 1 | |
| if(el.className || el.id) { | |
| tagInfo[1] += 1 | |
| } | |
| }) | |
| Object.keys(info).forEach((key) => { | |
| info[key].push(info[key][1] / info[key][0]) | |
| total[0] += info[key][0] | |
| total[1] += info[key][1] | |
| }) | |
| console.log(info) | |
| console.log('div', info.DIV) | |
| console.log('span', info.SPAN) | |
| console.log('total', total, total[1] / total[0]) | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment