如果我点击使用节点和createElement的按钮,我必须使文本变粗,但我真的不知道如何…
html(这是我想要加粗的文字):
Dies ist ein Text in einem P-Tag
JavaScript的:
function fettmachen(){
var neuB = document.createElement("b");
document.getElementById("textneu").insertBefore(neuB, document.getElementById("textneu").nextSibling);
}
我不知道它是如何工作的.
解决方法:
“I have to do it with nodes and createElement”
function fettmachen(){
// create the "b" element
var neuB = document.createElement("b");
// fetch the "textneu" element by ID
var textneu = document.getElementById("textneu");
// append the firstChild of "nextneu" to the "neuB"
neuB.appendChild(textneu.firstChild);
// append the "neuB" to the "nextneu"
nextneu.appendChild(neuB);
}
标签:javascript,nodes
来源: https://codeday.me/bug/20190714/1455391.html