Guest User

Untitled

a guest
Dec 13th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. // get the length of the longest classname in document
  2.  
  3. [].slice.call(document.querySelectorAll('body *')).filter(el => el.nodeType === 1 && typeof el.className === 'string').reduce( (m, el) => {
  4. const l = el.className.split(' ').filter(classname => classname.length > m).sort((a,b) => a.length - b.length).shift();
  5. return l ? l.length : m;
  6. },0)
  7.  
  8. // get the longest classname
  9.  
  10. [].slice.call(document.querySelectorAll('body *')).filter(el => el.nodeType === 1 && typeof el.className === 'string').reduce( (m, el) => {
  11. const l = el.className.split(' ').filter(classname => classname.length > m.length).sort((a,b) => a.length - b.length).shift();
  12. return l || m;
  13. },'')
  14.  
  15. // get the element with the longest class Attribute
  16.  
  17. [].slice.call(document.querySelectorAll('body *')).filter(el => el.nodeType === 1 && typeof el.className === 'string').reduce( (m, el) => {
  18. return el.className.length > m.className.length ? el : m;
  19. },document.body)
  20.  
  21. // get the element with the most classes
  22.  
  23. [].slice.call(document.querySelectorAll('body *')).filter(el => el.nodeType === 1 && typeof el.className === 'string').reduce( (m, el) => {
  24. return el.className.split(' ').length > m.className.split(' ').length ? el : m;
  25. },document.body)
Add Comment
Please, Sign In to add comment