Change hyperlink innerHTML by calling the setAttribute() function : setAttribute : HTML Tags JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » HTML Tags » setAttribute »

 

Change hyperlink innerHTML by calling the setAttribute() function

















<html>
<head>
<script language="JavaScript" type = "text/javascript">
<!--
function ChangeLink() {
    var newlink = document.getElementById("urltext");
    var curlink = document.getElementById("oldurl");
    curlink.href = ("http://" + newlink.value);
    curlink.innerHTML = newlink.value;
}

function NewWindow(prefval) {
    var curlink = document.getElementById("oldurl");
    if (prefval == 1)
    {
        curlink.setAttribute("target""_blank");
    }
    else if (prefval == 2)
    {
        curlink.removeAttribute("target");
    }
}
//-->
</script>
</head>
<body>
<form>
<a id="oldurl" href="http://www.navioo.com">www.navioo.com</a>
<P><input type="radio" value="V1" name="R1" onClick="NewWindow(1)">Open in New Window</p>
<P><input type="radio" name="R1" checked value="V2" onClick="NewWindow(2)">Open in Same Window</p>
   <input type="text" id="urltext" size="20">&nbsp;
   <input type="button" value="Change Link" name="B3" onClick="ChangeLink()"></p>
</form>
</body>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo HTML Tags
» setAttribute