JavaScript/hacks: Difference between revisions

Add querySelector example
No edit summary
 
Line 26: Line 26:
for (let i = 0; i < mainProducts.length; i++) {   
for (let i = 0; i < mainProducts.length; i++) {   
     result += `\n ${mainProducts[i].textContent.trim()}`;
     result += `\n ${mainProducts[i].textContent.trim()}`;
}
console.log(result);
</syntaxhighlight>Or the same exact example, used on a Testdox HTML report to list all the elements with CSS class "'''defect'''"<syntaxhighlight lang="javascript">
const bugs = document.querySelectorAll(".defect");
let result = '';
for (let i = 0; i < bugs.length; i++) { 
    result += `\n ${bugs[i].textContent.trim()}`;
}
}
console.log(result);
console.log(result);
</syntaxhighlight>
</syntaxhighlight>
[[Category:JavaScript]]
[[Category:JavaScript]]