Advertisement
elena1234

How to change display from none to block ( JavaScript)

Nov 16th, 2021 (edited)
1,456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let buttonForChooseStyle = document.getElementById('dropdown');
  3.     let dropDownUnorderList = document.getElementById('dropdown-ul');
  4.     let box = document.getElementById('box');
  5.  
  6.     buttonForChooseStyle.addEventListener('click', function () {  
  7.         if(dropDownUnorderList.style.display !== 'block') {  // !== 'block'
  8.             dropDownUnorderList.style.display = 'block';
  9.         }
  10.  
  11.         else {                                              // else
  12.             dropDownUnorderList.style.display = 'none';
  13.             box.style.color = 'white';
  14.             box.style.background = 'rgb(114, 112, 112)';
  15.         }
  16.     })
  17.  
  18.     dropDownUnorderList.addEventListener('click', e => {
  19.         let color = e.target.textContent;
  20.         box.style.color = 'black';
  21.         box.style.background = color;
  22.    })
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement