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.
Add a comment
|
1 Answer
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
Florian Margaine
Would you mind explaining why innerHTML is bad? It may not be in the DOM standard, but it clearly is a de-facto standard.
tckmn
@FlorianMargaine It's still better to conform to standards, and furthermore
createTextNode does escaping for you.Benjamin Gruenbaum
Mayuresh
still not working 4 me. Listen again I want to ad it from one location and to inside all of my webpages.
tckmn
@Mayuresh Umm... I don't understand what you're saying. Doesn't this add the text that you want?
|