js createElement
Posted 小兵
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js createElement相关的知识,希望对你有一定的参考价值。
?
http://www.w3schools.com/js/js_htmldom_nodes.asp
var child = document.getElementById("p1");
child.parentNode.removeChild(child);
?
http://www.w3schools.com/jsref/met_document_createelement.asp
var?btn = document.createElement("BUTTON");????????// Create a <button> element
var?t = document.createTextNode("CLICK ME");???????// Create a text node
btn.appendChild(t);????????????????????????????????// Append the text to <button>
document.body.appendChild(btn); ??
?
?
MSDN
https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
?
document.body.onload = addElement;
function addElement () {
// create a new div element
// and give it some content
var newDiv = document.createElement("div");
var newContent = document.createTextNode("Hi there and greetings!");
newDiv.appendChild(newContent); //add the text node to the newly created div.
// add the newly created element and its content into the DOM
var currentDiv = document.getElementById("div1");
document.body.insertBefore(newDiv, currentDiv); }
?
See also
?
以上是关于js createElement的主要内容,如果未能解决你的问题,请参考以下文章
js添加子元素 table tr td createElement