[英]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.