Advertisement
ilianrusev

Untitled

Feb 1st, 2022
23
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function focused() {
  2. let mainDiv = document.getElementsByTagName("div")[0];
  3.  
  4. Array.from(mainDiv.getElementsByTagName("input")).forEach(element => {
  5. element.addEventListener("focus",focus);
  6. });
  7.  
  8. Array.from(mainDiv.getElementsByTagName("input")).forEach(element => {
  9. element.addEventListener("blur",focusLost);
  10. });
  11.  
  12.  
  13. function focus(e) {
  14. let parent = e.target.parentNode;
  15. parent.classList.add("focused");
  16. }
  17.  
  18.  
  19. function focusLost(e) {
  20. let parent = e.target.parentNode;
  21. parent.classList.remove("focused");
  22. }
  23.  
  24. }
Advertisement
RAW Paste Data Copied
Advertisement