Skip to content

Instantly share code, notes, and snippets.

@rodebert
Last active December 11, 2017 13:34
Show Gist options
  • Save rodebert/72ca383be0149610cb62bc220ec4673d to your computer and use it in GitHub Desktop.
Save rodebert/72ca383be0149610cb62bc220ec4673d to your computer and use it in GitHub Desktop.
// 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