Javascript examples for DOM:Element setAttribute
Element setAttribute() Method - Find out if an <a> element has a target attribute. If so, change the value of the target attribute to "_self":
<!DOCTYPE html> <html> <body> <a id="myAnchor" href="http://www.java2s.com" target="_blank">go to java2s.com</a>. <button id="myBtn" onclick="myFunction()">Test</button> <script> function myFunction() {//w w w . j a v a 2 s . c o m var x = document.getElementById("myAnchor"); if (x.hasAttribute("target")) { x.setAttribute("target", "_self"); } } </script> </body> </html>