层次选择器当中的 $("ancestor desendant") 与 $("parent>child")的区别
来源:互联网 发布:下载淘宝注册 编辑:程序博客网 时间:2024/06/04 00:28
详细介绍一下jQuery层次选择器中ancestor descendant与parent>child的区别。
parent>child:根据父元素匹配所有的子元素,层次关系是父子关系。
ancestor descendant:根据祖先元素匹配所有的后代元素,层次关系是祖先和后代。
编写代码,进行测试,以更加清楚的区分两者的区别:
<div id="first">1
<span>1.1 </span>
<span>1.2 </span>
<div>1.3
<span>1.3.1 </span>
</div>
</div>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js">
</script>
<script type="text/javascript">
$(function () {
$("#first>span").css("color", "red");
});
</script>
运行后发现:
1.3.1的文字颜色不是红色,因为parent>child是父子关系;
如果把选择器改为:
$("#first span").css("color", "red");
则运行后发现:
1.3.1的文字颜色也是红色,因为ancestor descendant层次关系是祖先和后代。即id为"first"的元素下的所有span标记,不管是子辈,还是孙子辈,都会变成红色。
0 0
- 层次选择器当中的 $("ancestor desendant") 与 $("parent>child")的区别
- jQuery的parent > child选择器
- 在所给定的元素下寻找元素ancestor descendant 与在父元素下找元素 parent >child的区别
- jQuery中< parent > child >与< ance desc >的区别
- jQuery选择器:nth-child(even) 与:even的区别
- jquery选择器:nth-child()与空格:eq() 的区别;
- jquery 中 first 与 first-child选择器的区别
- 【jQuery】parent > child选择器
- $(“parent > child”)选择器
- 【JQuery】parent > child选择器
- :nth-child(index)和nth-child(index)选择器的区别
- jquery 层次选择器(siblings与nextAll的区别)
- Jquery中的层次选择器与find()的区别
- 关于窗口的Parent&Child关系与Owner&Owned关系
- parent > child选择器(jQuery)
- 2-7parent > child选择器
- Owner 与Parent 的区别
- opener与parent的区别
- STL Allocator
- 从零单排c++ primer(18)
- javafx开源库收集,不断更新。。。
- hdu 1159公共子序列
- 二维数组数组
- 层次选择器当中的 $("ancestor desendant") 与 $("parent>child")的区别
- WEB模式与图书馆模式探讨
- 从mongodb移除分片
- Oracle 11g sys,system 密码忘记设置解决办法
- what should you be as a programmer?To be the last one and become experienced!
- mysql学习之路一linux启动mysql
- 八大排序算法
- CentOS文件备份|还原
- "我不比健全人差" 盲人大学生成首位视障程序员