Advertisement
GeorgiLukanov87

09. Highlight Active

Feb 23rd, 2023
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 09. Highlight Active
  2.  
  3. // variant 1
  4. function focused() {
  5.     inputElement = document.querySelectorAll('div div input')
  6.     let activeElement = document.activeElement;
  7.  
  8.     for (inputEl of inputElement) {
  9.         inputEl.addEventListener('focusin', (e) => {
  10.             e.currentTarget.parentNode.classList.add('focused')
  11.         })
  12.        
  13.         inputEl.addEventListener('focusout', (e) => {
  14.             e.currentTarget.parentNode.classList.remove('focused')
  15.         })
  16.     }
  17.  
  18. }
  19.  
  20. //variant 2
  21. function focused() {
  22.     let divs = document.querySelectorAll('div div input');
  23.    
  24.     for (let div of divs) {
  25.         div.addEventListener('focusin', () => {
  26.             div.parentNode.classList.add('focused');
  27.         });
  28.        
  29.         div.addEventListener('focusout', () => {
  30.             div.parentNode.classList.remove('focused');
  31.         });
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement