Hello Guys,

I am working on coding a Javascript that will watch for a click event on an href that does not have an id or class. The links are generated automatically and I can't add an ID or Class to them. I need the script to watch for the click event and use a target = "_Blank" to open a new window.

Any help would be appreciated.

This is what I have so far but doesn't work.

Here my code

HTML

<a href="http://test.com/resources/blog/">Blog</a>

JS

document.addEventListener("click", function (e) {

if (e.event.target.href == "http://test.com/resources/blog/" && !e.target.hasAttribute("target")) {
e.target.setAttribute("target", "_blank");
}
});