Advertisement
Todorov_Stanimir

07. Locked Profile Exercise: DOM Manipulations

Oct 13th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lockedProfile() {
  2.     [...document.getElementsByTagName('button')].map(but => but.addEventListener('click', function (e) {
  3.         mapper = {
  4.             'Show more': () => ['block', 'Hide it'],
  5.             'Hide it': () => ['none', 'Show more']
  6.         };
  7.         if (!e.target.parentElement.querySelector('input[type=radio]').checked) {
  8.             e.target.parentElement.querySelector('div').style.display = mapper[e.target.textContent](e)[0];
  9.             e.target.parentElement.querySelector('button').textContent = mapper[e.target.textContent](e)[1];
  10.         };
  11.     }));
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement