I've been trying to follow the example from the sitepoint book on DHTML to change the href property of a link, but it doesn't work no matter what I try. Here's the code in the HTML file:
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Javascript testing </title>
<script type="text/javascript" src="js/main.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<a href="http://www.yahoo.com" id="changeMe">Yahoo </a>
</body>
</html>
Here's the code in 'js/main.js' file:
PHP Code:
changeLink();
function changeLink()
{
var linkToChange = document.getElementById('changeMe')
linkToChange.href="http://www.google.com";
alert('done!');
return true;
}
Whenever I try to run this, the mozilla console gives this error:

Originally Posted by
mozilla
What am I doing wrong??
Edit: Nevermind, I just fixed this problem by moving the line that calls up main.js at the end of all the html and it worked.
Bookmarks