Advertisement
svetlyoek

Untitled

Jun 9th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. function solve() {
  2.  
  3. const styleBtn = document.getElementById('dropdown');
  4. const box = document.getElementById('box');
  5. const list = document.getElementById('dropdown-ul');
  6. const colors = document.querySelectorAll('#dropdown-ul > li');
  7.  
  8. styleBtn.addEventListener('click', function (e) {
  9. e.preventDefault();
  10.  
  11. if (list.style.display !== 'block' && box.style.backgroundColor === '') {
  12.  
  13. list.style.display = 'block';
  14.  
  15. colors.forEach(l => l.addEventListener('click', function (e) {
  16. e.preventDefault();
  17.  
  18. let color = e.target.textContent;
  19.  
  20. box.style.backgroundColor = color;
  21. }));
  22. } else if (box.style.backgroundColor !== '') {
  23.  
  24. list.style.display = 'none';
  25.  
  26. box.style.backgroundColor = '';
  27. }
  28. });
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement