0

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

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.

Sign up to request clarification or add additional context in comments.

8 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.