Long Con Posted September 7, 2010 Share Posted September 7, 2010 In my script tags in the head, I have:document.getElementById("mainLink").href = "http://www.google.com/";And in the body of the HTML, I have:<a id=mainLink" target="_blank">LinkText</a>But it's not working... what am I doing wrong? Link to comment Share on other sites More sharing options...
Synook Posted September 7, 2010 Share Posted September 7, 2010 You are probably trying to modify the #mainLink element before it is created - either place that JavaScript code after the tag, or set it to run when the page finishes loading. Link to comment Share on other sites More sharing options...
thescientist Posted September 7, 2010 Share Posted September 7, 2010 In my script tags in the head, I have:document.getElementById("mainLink").href = "http://www.google.com/";And in the body of the HTML, I have:<a id=mainLink" target="_blank">LinkText</a>But it's not working... what am I doing wrong?is it a type that you forgot the opening quote for the id attribute on the anchor element? Link to comment Share on other sites More sharing options...
Long Con Posted September 7, 2010 Author Share Posted September 7, 2010 is it a type that you forgot the opening quote for the id attribute on the anchor element?OMG yes. Link to comment Share on other sites More sharing options...
ShadowMage Posted September 7, 2010 Share Posted September 7, 2010 OMG yes. Yes it's a typo? In your posted code? Or you actual code?This is one good reason it always pays to validate your code. Link to comment Share on other sites More sharing options...
jeffman Posted September 7, 2010 Share Posted September 7, 2010 OMG suggests the error is in the actual code. It happens. A quick look at the Firefox Error Console would have turned up the error also. It would have reported something like "object not found" or "mainLink" does not exist. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.