JavaScript/hacks: Difference between revisions

No edit summary
Add querySelector example
Line 19: Line 19:
      
      
}  
}  
console.log(result);
</syntaxhighlight>Here's another example, using <code>querySelector()</code> and [https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll <code>querySelectorAll()</code>] with class names<syntaxhighlight lang="javascript">
const container = document.querySelector( ".NavigationItem-items-container");
const mainProducts = container.querySelectorAll( ".NavigationGroup-title, .NavigationLink-title");
let result = '';
for (let i = 0; i < mainProducts.length; i++) { 
    result += `\n ${mainProducts[i].textContent.trim()}`;
}
console.log(result);
console.log(result);
</syntaxhighlight>
</syntaxhighlight>
[[Category:JavaScript]]
[[Category:JavaScript]]