DOM的全称为文档对象模型,英文:Document Object
Model。DOM与家谱有几分类似,同其它标记语言一样,HTML也使用这个模型来描述页面中元素之间的关系。如
<HTML> <------这是祖先元素
<body> <------这是子元素
<div> <----div是body的子元素
<p>这是个一个段落。<----P是DIV的子元素
</div>
</body>
</HTML>
那么JQUERY怎么获取DOM对象呢?
答案是:工厂函数:$()
如上DOM,则用$('p')可得到当前的文档中的所有段落
应用:给所有段落增加一个CSS类
CSS:
.p-style{
background:#CCCCCC;
}
javascript:
$('document').ready(function(){
$('p').addClass('p-style');
})
注:以上代码没有进过测试,目的就是说明一下$的用法和DOM对象