Last active
December 11, 2017 13:34
-
-
Save rodebert/72ca383be0149610cb62bc220ec4673d to your computer and use it in GitHub Desktop.
This file contains 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
// get the length of the longest classname in document | |
[].slice.call(document.querySelectorAll('body *')).filter(el => el.nodeType === 1 && typeof el.className === 'string').reduce( (m, el) => { | |
const l = el.className.split(' ').filter(classname => classname.length > m).sort((a,b) => a.length - b.length).shift(); | |
return l ? l.length : m; | |
},0) | |
// get the longest classname | |
[].slice.call(document.querySelectorAll('body *')).filter(el => el.nodeType === 1 && typeof el.className === 'string').reduce( (m, el) => { | |
const l = el.className.split(' ').filter(classname => classname.length > m.length).sort((a,b) => a.length - b.length).shift(); | |
return l || m; | |
},'') | |
// get the element with the longest class Attribute | |
[].slice.call(document.querySelectorAll('body *')).filter(el => el.nodeType === 1 && typeof el.className === 'string').reduce( (m, el) => { | |
return el.className.length > m.className.length ? el : m; | |
},document.body) | |
// get the element with the most classes | |
[].slice.call(document.querySelectorAll('body *')).filter(el => el.nodeType === 1 && typeof el.className === 'string').reduce( (m, el) => { | |
return el.className.split(' ').length > m.className.split(' ').length ? el : m; | |
},document.body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment