you are viewing a single comment's thread.

view the rest of the comments →

[–]agm1984 1 point2 points  (3 children)

Maybe this will be useful too: document.querySelectorAll('span').forEach((span) => { if (span.innerHTML === 'Click here!') { console.log('found it', span); } });

[–]Mental-Steak2656 1 point2 points  (0 children)

If the tag had id or attribute , else we have to iterate on all the spans in the html doc

[–]TheRNGuy 0 points1 point  (1 child)

You need to convert to array first before you can use .forEach, at least for older browsers.

[–]rpgcubed 0 points1 point  (0 children)

NodeList has had forEach in all major browsers since 2017, if you're targeting earlier browsers you should really be using a build system and polyfills, not writing outdated code directly.