I am trying to insert some new links using ‘innerHTML’. As there may be a number of calls on the same ‘ids’ I thought it would be wise to use variables. The following does not respond beyond the alert? The process works fine if I don’t use ‘var link’ and just enter it in full. Is there an issue perhaps trying to do this with xhtml?
Thanks.
Code:
var newlink = '<a title="new link" href="newlink.htm">New Link</a>';
var link = "document.getElementById('idlink')";
if( link ) {
alert("link confirmed");
link.innerHTML = newlink;
}
This was more or less the problem. I was assigning the 'var link' in the head of the document. If I assign it further down the page after the element it works fine.
Presumably if I put the variable in an external.js this will also have to be loaded after the element?