Advertisement
elena1234

removeAttribute ( JavaScript)

Nov 23rd, 2021
944
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let tBody = document.getElementsByTagName('tbody')[0];
  3.     let trArray = Array.from(document.getElementsByTagName('tr'));
  4.     tBody.addEventListener('click', e => {
  5.         let target = e.target;
  6.         let currentRow = target.parentElement;
  7.         if (currentRow.getAttribute("style") == null || currentRow.getAttribute("style") == "") {
  8.             trArray.map(tr => tr.removeAttribute('style'));
  9.             currentRow.style.backgroundColor = "#413f5e";
  10.  
  11.         } else {
  12.             currentRow.removeAttribute('style');
  13.         }
  14.     })
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement