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


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


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

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