码迷,mamicode.com
首页 > Web开发 > 详细

js createElement

时间:2016-03-12 01:28:23      阅读:316      评论:0      收藏:0      [点我收藏+]

标签:

?

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

标签:

原文地址:http://www.cnblogs.com/icenter/p/5267674.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!