From this answer of mine. The code works well on jsfiddle, but doesn't work on the Stackoverflow's snippet. By "works" I mean I want it to open https://www.google.com/ on a new tag, which is what the OP of that question wants.
I open the console when running on the Stackoverflow snippet and this is the error message:
Is there any way to make my answer work well even on the Stackoverflow snippet (which make its demonstration more attractive)?
document
.querySelectorAll("a.fresh")
.forEach(a => {
a.setAttribute("target", "_blank")
});
a.fresh {
text-decoration: none;
}
<a class="fresh" href="https://www.google.com/">link1</a>
<a class="fresh" href="https://www.google.com/">link2</a>