Jump to content

Create link with javascript


Long Con

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...