Advertisement
kstoyanov

04. Locked Profile

Oct 1st, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lockedProfile() {
  2.     Array.from(document.querySelectorAll('.profile button')).forEach((btn) =>
  3.         btn.addEventListener('click', showMoreHandler)
  4.     );
  5.  
  6.     function showMoreHandler(e) {
  7.         const moreContent = this.previousElementSibling;
  8.         const displayStatus = this.previousElementSibling.style.display;
  9.         const locked = this.parentElement.querySelector('input[value=lock]')
  10.             .checked;
  11.  
  12.         if (locked) return;
  13.  
  14.         if (displayStatus === 'none' || displayStatus.length === 0) {
  15.             moreContent.style.display = 'block';
  16.             this.textContent = 'Hide it';
  17.         } else {
  18.             if (locked) return;
  19.             moreContent.style.display = 'none';
  20.             this.textContent = 'Show more';
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement