Home >Web Front-end >JS Tutorial >Basic knowledge of Dom node creation_DOM

Basic knowledge of Dom node creation_DOM

WBOY
WBOYOriginal
2016-05-16 18:01:241046browse
复制代码 代码如下:

var body = document.body;
var html = document.documentElement;
var div = document.createElement("div");
var p = document.createElement("p");
var ali = document.createTextNode("alipay");
p.appendChild(ali);
div.appendChild(p);
div.setAttribute("id","fn-div");
div.setAttribute("class","fn-class");
body.appendChild(div);

var arr = div.attributes;
for(var i=0;iconsole.log(arr[i].name ":" arr[i].value);
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn