-5

document.getElementById("mahacareer").onclick = function () {
 location.href = "http://www.mahacareermitra.in";
};
<a href="" target="_blank" id="mahacareer">Access the portal</a>

hello i want to open above link in new tab when i click on it.we use target="_blank" attribute with a tag but i want to use that attribute with JavaScript.

Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73

1 Answers1

0

You can use

window.open('http://www.mahacareermitra.in','_blank');

or

You can use SetAttribute function in java script.

<a href=""  id="mahacareer">Access the portal</a>

Try this

  document.getElementById("mahacareer").setAttribute("target", "_blank"); 
Gokulan P H
  • 1,838
  • 1
  • 10
  • 13