Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

vanilla js for each element add attribute

const linksArray = Array.from(document.querySelectorAll('section a')); // we use Array.from to transform the NodeList from querySelectorAll to an array. Needs to IE11

linksArray.forEach(linkEl => { // we search for every span and em inside the link
 linkEl.setAttribute("list-span", linkEl.querySelector('span').textContent);
 linkEl.setAttribute("list-em", linkEl.querySelector('em').textContent);
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #vanilla #js #element #add #attribute
ADD COMMENT
Topic
Name
7+2 =