replacing div content with javascript

后端 未结 6 2181
悲&欢浪女
悲&欢浪女 2020-12-09 01:48

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

6条回答
  •  被撕碎了的回忆
    2020-12-09 01:54

    clear the div:

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

    replace it :

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

提交回复
热议问题