Advertisement
kstoyanov

04. Dropdown Menu

Oct 4th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     const chooseYourStyleButton = document.getElementById('dropdown');
  3.     const dropdownElement = document.getElementById('dropdown-ul');
  4.     const outputBox = document.getElementById('box');
  5.  
  6.     chooseYourStyleButton.addEventListener('click', (e) => {
  7.       const currentDisplayStyle = dropdownElement.style.display;
  8.       if (!currentDisplayStyle || currentDisplayStyle === 'none') {
  9.         dropdownElement.style.display = 'block';
  10.       } else {
  11.         dropdownElement.style.display = 'none';
  12.         outputBox.style.backgroundColor = 'black';
  13.         outputBox.style.color = 'white';
  14.       }
  15.     });
  16.  
  17.     dropdownElement.addEventListener('click', (e) => changeColor.call(e.target, e));
  18.  
  19.     function changeColor() {
  20.       console.log(this.tagName);
  21.       if (this.tagName !== 'LI') { return; }
  22.       outputBox.style.backgroundColor = this.textContent;
  23.       outputBox.style.color = 'black';
  24.     }
  25. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement