Hi I am building an HTML site & to place ads inside that I need a javascript code to change it or update it from on script page not by going every page & cut/paste that ad code. I entered this in script page document.getElementById.('adcode').innerHTML('HTML code provided by ad networks');
And in my website I used this code <div id="adcode"> </div>
But it is not showing anything even if I entered any other HTML code.
1 Answer 1
document.getElementById('adcode').innerHTML = 'HTML code provided by ad networks';
innerHTML is not a function, it is a variable. ALso, you had a . after getElementById.
A better way, however, would be something like this:
var text = document.createTextNode('HTML code provided by ad networks');
document.getElementById('adcode').appendChild(text);
If you use this method, the text will be automatically escaped for you.
8 Comments
createTextNode does escaping for you.