Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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)
Add Comment
Please, Sign In to add comment