vanilla js for each element add attribute

Solutions on MaxInterview for vanilla js for each element add attribute by the best coders in the world

showing results for - "vanilla js for each element add attribute"
Jannik
06 Nov 2019
1const linksArray = Array.from(document.querySelectorAll('section a')); // we use Array.from to transform the NodeList from querySelectorAll to an array. Needs to IE11
2
3linksArray.forEach(linkEl => { // we search for every span and em inside the link
4 linkEl.setAttribute("list-span", linkEl.querySelector('span').textContent);
5 linkEl.setAttribute("list-em", linkEl.querySelector('em').textContent);
6});
7