As we know we can associate some
JavaScript function with am
HTML button or an image and we used
JavaScript on buttons images, same
way can be follow with hyperlinks. The code to associate some JavaScript
function on Hyperlink will be as under.
In this example we can change the text and the URL of a hyperlink. We can also
change the target attribute for the hyperlink. The target attribute is by
default set to "_self", which means that the link will open in the same window.
By setting the target attribute to "_blank", the hyperlink will open in a new window
as shown in below code.
<html>
<head>
<script type="text/javascript">
function changeLink()
{
document.getElementById('anchor').innerHTML="Explore Google Technologies"
document.getElementById('anchor').href="
https://www.google.com"
document.getElementById('anchor').target="_blank"
}
</script>
</head>
<body>
<a id="anchor" href="
https://www.globalguideline.com">
Explore JavaScript Tutorial at Global Guide Line
Technologies.
</a>
<u><font color="#0000FF">
<a href="javascript:changeLink()" target="_self">
Change above Hyperlink, JavaScript is waiting for
action
</a>
</font></u>
</body>
</html>