1.节点相关的操作
getElementById()
getElementByName()
getElementsByClassName()
getElementsByTagName()
getAttribute():获取元素属性
setAttribute():设置元素属性
childNodes():访问子节点
parentNode():访问父节点
createElement():访问元素
createTextNode():创建元素节点
appendChild():在末尾添加节点
insertBefore():插入节点
removeChild():删除节点
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<a id="link" href="http://www.baidu.com">百度</a>
<script>
var linkList=document.getElementById("link");
var linkA=linkList.getAttribute("href");
document.write(linkA); //以文档的形式输出网页中
linkList.setAttribute("href","http://www.3g.qq.com");//修改属性为href的值
linkList.style.color="red";//将a标签中的字体设为红色
</script>
</body>
</html>
删除节点
document.getElementsByTagName("body")[0].removeChild(link);//已知父节点
link.parentNode.removeChild(link); //未知父节点