对于如下代码片段  如何对河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. Dialog with HTML skin using CDHtmlDialog and SetWindowRgn

    Introduction This program demonstrates how to use CDHtmlDialog and SetWindowRgn functions to give a ...

  2. HTML5API___manifest

    离线缓存 manifest 在html标签里面增加个属性 mainfest 就可以告诉浏览器缓存文件在哪里. <html manifest='show.manifest' xmlns=" ...

  3. Studious Student Problem Analysis

    (http://leetcode.com/2011/01/studious-student-problem-analysis.html) You've been given a list of wor ...

  4. Problem A: 走迷宫问题

    Problem A: 走迷宫问题Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 9 Solved: 3[Submit][Status][Web Board] ...

  5. Queue(队列)

    队列是一种后进后出的数据结构,下面介绍一下队列中常见的函数: 一.queue 中的 empty 函数 queue<int> q ; q.empty() ;  // 若队列中无元素,返回tr ...

  6. HDU 3729 二分匹配 反向匹配

    题意: 给定 n个学生 说的 自己 考试排名的 可能范围 确定最多几个人说真话 如果有多种答案,输出字典序最大的那种( 要求字典序最大,所以solve中从最大字典序开始匹配) 思路: 题目给定  点 ...

  7. hadoop配置及无法移动文件到hdfs故障解析

    首先博主用的64位ubuntu,hadoop官方只提供32位版本,这样的话启动本地库无法兼容,需要自己编译为64位版本,或下载别人编译好的64位版本. 下载好需要在etc/hadoop目录下改动以下几 ...

  8. mybatis一对一关联表查询

    先创建一个表 CREATE TABLE teacher( t_id INT PRIMARY KEY AUTO_INCREMENT, t_name ) ); CREATE TABLE class( c_ ...

  9. SubLime BracketHighlighter 配置

    很多插件在github上都有比较详细的说明  告知安装位置什么的一般来说 插件都是放在Packages目录里面的   从Github上下载 解压得到的文件夹然后放入到Packages中这个目录在哪里呢 ...

  10. Bootstrap Collapse使用

    参考 http://wrongwaycn.github.io/bootstrap/docs/javascript.html#collapse http://www.w3resource.com/twi ...