对于如下代码片段  如何对河meishi这个div的子DIV呢?

<div id="vertical-Menu-meishi" class="J-nav-item">
<div id="yui_3_12_0_1_1387858313977_228" >
<div id="yui_3_12_0_1_1387858313977_227" ></div>
<div id="yui_3_12_0_1_1387858313977_424" ></div>
</div>
</div>

参考http://api.jquery.com/first-child-selector/

http://api.jquery.com/nth-child-selector/

不过上述都没有说明  :nth-child(2) 可以用在children()的括号中...

不过想想  :nth-child(2)本身是选择器表达式   children('selector')  括号中也是选择器表达式

所以它就干脆没说

stackoverflow上又两个问答也很好的

http://stackoverflow.com/questions/4727263/jquery-get-second-child

http://stackoverflow.com/questions/5440792/getting-the-2nd-child-element

(后一篇中第一个回答的方案3 似乎行不通)

        $("#yui_3_12_0_1_1387858313977_424").css('display', 'block');//ok
//表示的是获取#vertical-Menu-meishi下得第一个DIV元素
alert($("#vertical-Menu-meishi div:first-child").attr("id"));//ok
alert( ($("#vertical-Menu-meishi").children(':first-child')).attr("id"));//ok
//获取第一个子元素的第一个子元素
alert( $("#vertical-Menu-meishi").children(':first-child').children(':first-child').attr('id') );//ok
//获取第一个子元素的第二个子元素
alert( $("#vertical-Menu-meishi").children(':first-child').children(':nth-child(2)').attr('id') );//ok //或者使用下面的办法 感觉更加容易理解
//获取第一个子元素
alert( $("#vertical-Menu-meishi").children('div').eq(0).attr('id') );//ok
获取第一个子元素下的第二个子元素
alert( $("#vertical-Menu-meishi").children('div').eq(0).children('div').eq(1).attr('id') );//ok

显然后面几种方式更好  第一个的话  第一种形式 对于$(this)这样的表达式就无能为力啦

jQuery 子元素选择的更多相关文章

  1. jquery 子元素 后代元素 兄弟元素 相邻元素

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...

  2. jQuery——子元素筛选器

    子元素筛选器 名称 :first-child JQ语法 jQuery( "selector:first-child" ) 说明 :first-child选择器用于匹配作为父元素的第 ...

  3. 一个样例看清楚JQuery子元素选择器children()和find()的差别

    近期在我们的hybrid app项目开发中定位出了一个问题.通过这个问题了解下JQuery选择器find()和children()的差别.问题是这种:我们的混合app是一个单页面应用(main.htm ...

  4. jquery 子元素筛选选择器

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...

  5. jquery子元素选择器

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. jquery子元素过滤选择器

    :nth-child('索引值')//获取指定元素下的某个子元素的位置,索引从1开始: //偶数行                 //$('li:nth-child(even)').addClass ...

  7. jquery子元素过滤器

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  8. jQuery内容过滤选择器与子元素过滤选择器用法实例分析

    jQuery选择器内容过滤 一.:contains(text) 选择器::contains(text)描述:匹配包含给定文本的元素返回值:元素集合 示例: ? 1 2 $("div.mini ...

  9. 深入学习jQuery选择器系列第八篇——过滤选择器之伪子元素选择器

    × 目录 [1]通用形式 [2]反向形式 [3]首尾元素 [4]唯一元素 前面的话 本文是子元素选择器的续篇,主要介绍关于nth-of-type()选择器的内容.该部分内容并非没有出现在<锋利的 ...

随机推荐

  1. Codeforces 713C Sonya and Problem Wihtout a Legend(单调DP)

    [题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上 ...

  2. CodeForces 160D - Distance in Tree 树型DP

    题目给了512MB的空间....用dp[k][i]代表以k为起点...往下面走(走直的不打岔)i步能有多少方案....在更新dp[k][i]过程中同时统计答案.. Program: #include& ...

  3. python 命令行参数,以及文件操作

    #demo.py #!/usr/bin/python import sys print sys.argv #python demo.py 11 22 33 44 55 ['demo.py', '11' ...

  4. JavaScript基础(语法类型转换、运算符、语句)

    1.类型转换: 分为自动转换和强制转换,一般用强制转换. 其他类型转换为整数:parseint(): 其他类型转换为小数:parsefloat(): 判断是否是一个合法的数字类型:isNaN(): 是 ...

  5. linux查看和设置系统时间 hwclock && date

    http://www.linuxso.com/command/hwclock.html查看时间{1. date查看系统时钟, hwclock查看硬件时钟hwclock && date ...

  6. Android应用开发基础篇(12)-----Socket通信

    链接地址:http://www.cnblogs.com/lknlfy/archive/2012/03/03/2378669.html 一.概述 网络通信无论在手机还是其他设备上都应用得非常广泛,因此掌 ...

  7. appium获取app应用的package和 activity。---新手总结(大牛勿喷,新手互相交流)

    从网上搜索的方法: 如下: 1.查看源码 2.日志法a.启动待测apkb.开启日志输出:adb logcat>D:/log.txtc.关闭日志输出:ctrl+cd.查看日志直接搜索 :Displ ...

  8. JS性能

    获取以下属性  会等待对应元素渲染完成  才继续执行 * offsetTop, offsetLeft, offsetWidth, offsetHeight* scrollTop, scrollLeft ...

  9. QTP 9.2 下载&破解

    版本不同 但是破解总是这个 crack文件下载 http://ishare.iask.sina.com.cn/f/13802744.html   QTP9.2 下载地址 http://www.duot ...

  10. Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

    2016-07-18 16:08:20 [main:53] - [WARN] Exception encountered during context initialization - cancell ...