用javascript替换div内容 [英] replacing div content with javascript

查看:93
本文介绍了用javascript替换div内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用纯javascript,而不是使用jquery。我的div有一个id test 并且里面包含其他div。如何清空此div的内容并将其替换为其他html?

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 it with other html?

<div id="test">
   <div>...</div>
   <div>...</div>
   <div>...</div>
</div>


推荐答案

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

这篇关于用javascript替换div内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆