Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

常用Dom节点总结 #5

Open
gaowei1012 opened this issue Jun 14, 2017 · 0 comments
Open

常用Dom节点总结 #5

gaowei1012 opened this issue Jun 14, 2017 · 0 comments

Comments

@gaowei1012
Copy link
Owner

gaowei1012 commented Jun 14, 2017

1.访问/获取节点

getElementById(id);           //返回对拥有指定id的第一个对象进行访问
getElementsByName(name);      //返回带有指定名称的节点集合
getElementsByTagName(tagname);   //返回带有指定标签名的对象集合
getElementsByClassName(classname);  //返回带有指定class名称的对象集合

2.创建节点/属性

document.createElement(eName);  //创建一个节点
document.createAttribute(attrName); //对某个节点创建属性
document.createTextNode(text);   //创建文本节点

3.添加节点

document.insertBefore(newNode,referenceNode);  //在某个节点前插入节点
parentNode.appendChild(newNode);        //给某个节点添加子节点

4.复制节点

cloneNode(true | false);  //复制某个节点  参数:是否复制原节点的所有属性

5.删除节点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant