Advertisement
Ivankooo1

functionExercise

Sep 16th, 2020
1,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(){
  2.  
  3.    let tBody = document.querySelector('tbody');
  4.    let items = tBody.querySelectorAll('tr');
  5.  
  6.    tBody.addEventListener('click', onClick);
  7.  
  8.  
  9.        function onClick(e){
  10.      
  11.          let tr = e.target.parentNode;
  12.      
  13.          if(tr.nodeName === 'TR'){
  14.  
  15.             if(tr.style.backgroundColor !== ""){
  16.                tr.style.backgroundColor = "";
  17.    
  18.             }else{
  19.                [...items].forEach(i => i.style.backgroundColor = '');
  20.                tr.style.backgroundColor = '#413f5e';
  21.             }
  22.          }
  23.  
  24.        }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement