<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
</head>
<body>
<ul class="level-1">
<li class="item-i">I</li>
<li class="item-ii">II
<ul class="level-2">
<li class="item-a">A</li>
<li class="item-b">B
<ul class="level-3">
<li class="item-1">1</li>
<li class="item-2">2</li>
<li class="item-3">3</li>
</ul>
</li>
<li class="item-c">C</li>
</ul>
</li>
<li class="item-iii">III</li>
</ul>
<script>$('ul.level-2').children().eq(2).css('background-color', 'red');</script>
</body>
</html>

解释:children() 是儿子节点,与孙子节点是无关的。

结果如图:

children() 和find() 的区别。

如果是find(),eq(2)会把 整个的 第二个li 给算上。find() 会把孙子节点也算上。

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
</head> <body>
<ul class="level-1">
<li class="item-i">I</li>
<li class="item-ii">II
<ul class="level-2">
<li class="item-a">A</li>
<li class="item-b">B
<ul class="level-3">
<li class="item-1">1</li>
<li class="item-2">2</li>
<li class="item-3">3</li>
</ul>
</li>
<li class="item-c">C</li>
</ul>
</li>
<li class="item-iii">III</li>
</ul> <script>
$('li.item-ii').find('li').eq(2).css('background-color', 'red');
</script> </body>
</html>

结果如下:

jQuery 中的children()和 find() 的区别的更多相关文章

  1. jquery中的children()和contents()的区别

    1.children()只会返回元素节点 2.contents()还可以返回文本节点

  2. jquery遍历之children()与find()的区别

    hildren(selector) 方法是返回匹配元素集合中每个元素的所有子元素(仅儿子辈).参数可选,添加参数表示通过选择器进行过滤,对元素进行筛选. .find(selector)方法是返回匹配元 ...

  3. jQuery中的bind() live() delegate()之间区别分析

    jQuery中的bind() live() delegate()之间区别分析 首先,你得要了解我们的事件冒泡(事件传播)的概念,我先看一张图 1.bind方式 $('a').bind('click', ...

  4. 深入理解jQuery中live与bind方法的区别

    本篇文章主要是对jQuery中live与bind方法的区别进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助 注意如果是通过jq添加的层和对象一定要用live(),用其他的都不起作用 ...

  5. jQuery中attr和prop方法的区别说明

    jquery中attr和prop的基本区别可以理解为:如果是内置属性,建议用prop,如果是自定义的建议用attr. 例如 <input type=check  node=123 id=ck & ...

  6. jquery中的$().each和$.each的区别

    jquery中的$().each和$.each的区别 注意:jquery中的$().each和$.each的区别,前者只能遍历数组,后者可以遍历数组和对象 备注:sinobook项目中地名本体相关地按 ...

  7. jQuery中attr和prop方法的区别

    jQuery中attr和prop方法的区别。 http://my.oschina.net/bosscheng/blog/125833 http://www.javascript100.com/?p=8 ...

  8. jquery中的this与$(this)的区别总结(this:html元素)($(this):JQuery对象)

    jquery中的this与$(this)的区别总结(this:html元素)($(this):JQuery对象) 一.总结 1.this所指的是html 元素,有html的属性,可用 this.属性  ...

  9. jquery中this与$(this)的用法区别

    jquery中this与$(this)的用法区别.先看以下代码: $("#textbox").hover( function() { this.title = "Test ...

随机推荐

  1. ERR: Call to undefined function openssl_random_pseudo_bytes()

    最近使用TP5/PHP7,总是出现ERR: Call to undefined function index\index\openssl_random_pseudo_bytes(),才发现是php没有 ...

  2. In_interrupt( ) 和In_irq( )【转】

    转自:http://blog.csdn.net/do2jiang/article/details/5486888 in_interrupt() 是判断当前进程是否处于中断上下文,这个中断上下文包括底半 ...

  3. jython学习笔记2

    1.%是求余,//是整除的商,**是乘方 abs(var) Absolute value pow(x, y) Can be used in place of ** operator pow(x,y,m ...

  4. AVAudioplayer时error解决 创建失败 ERror creating player: Error Domain=NSOSStatusErrorDomain Code=2003334207 "(null)"

    AVAudioplayer 有两个初始化方法: 1.[[AVAudioPlayer alloc] initWithData:musicData error&e]; 2.[[AVAudioPla ...

  5. 以雅酷网为实例从技术上说说dedecms的seo优化要注意哪些?

    目前在做雅酷网 ,雅酷卡是雅酷时空公司的产品,我个人感觉用雅酷卡消费还是比较实惠的,而雅酷卡的特色便是雅酷健身卡,很多站长成天的趴电脑上,可以考虑办一张这样的卡,在周末的时候去健身中心活动活动,还是比 ...

  6. ACM题目————还是畅通工程

    Submit Status Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路 ...

  7. android FragmentPagerAdapter getItem方法没有执行

    转自 http://blog.csdn.net/getchance/article/details/40263505 在一个 Android 应用中,我使用 FragmentPagerAdapter  ...

  8. c#sqlhelper之用法

    MySqlParameter[] a=new MySqlParameter[]{new MySqlParameter("@stu_id",stu_id)}; 参数使用

  9. 《python核心编程》读书笔记--第15章 正则表达式

    15.1引言与动机 处理文本和数据是一件大事.正则表达式(RE)为高级文本匹配模式,为搜索-替换等功能提供了基础.RE是由一些字符和特殊符号组成的字符串,它们描述了这些字符和字符串的某种重复方式,因此 ...

  10. 异步I/O

    http://blog.csdn.net/gotosola/article/details/7412409 Linux2.6异步I/O AIO的基本思想:  允许进程发起很多I/O操作,而不用阻塞或等 ...