[英]How can I remove the tag's text with Javascript, only the text not tag
HTML:
<h2>
Available courses
<span>Available courses</span>
</h2>
脚本:
var textCon1 = document.querySelector("#frontpage-course-list h2");
var textCon2 = document.querySelector("#frontpage-course-list h2").innerHTML;
var createSpan = document.createElement("span");
createSpan.innerHTML = textCon2;
textCon2.appendChild(createSpan);
textCon1.innerHTML="";
在这里,我试图删除h2标签中可用的文本,但是它将删除h2标签中可用的所有内容。 我想保留文本的span标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.