Skip to content Skip to sidebar Skip to footer

Replacing Div Content With Javascript

I'm trying to do this with pure javascript, not with jquery. I have a div that has an id test and contains other divs inside it. How do I empty the content of this div and replace

Solution 1:

document.getElementById("test").innerHTML = "new content"

Solution 2:

clear the div:

document.getElementById('test').innerHTML = '';

replace it :

var h1 = document.createElement('h1');
h1.innerHTML = "hello world!";
document.getElementById('test').appendChild(h1);

Solution 3:

Off the top of my head, I think this should work....

document.getElementById("test").innerHTML = "";

Solution 4:

Use document.getElementById('test').innerHTML = ''.

Solution 5:

document.getElementById("test").innerHTML = "Some other Content";

Post a Comment for "Replacing Div Content With Javascript"