ch...">
美文网首页
jQuery选择器之层级选择器

jQuery选择器之层级选择器

作者: 光光的杂货铺 | 来源:发表于2017-01-23 12:51 被阅读0次

    级选择器

    元素之间的关系
    子选择器 child:parent后的直接子元素
    写法:$("parent > child")
    后代选择器 anyone:parent下面的所有元素
    写法:$("parent anyone")
    相邻兄弟选择器 所有紧接在brother之后的young brother元素
    写法:$("brother + young brother"),记忆方法:兄弟心连心,所以兄弟元素的获取用加号;
    一般兄弟选择器: 获取myself元素之后所有的neighbor元素
    写法:$("brother ~ young brother")

    相邻兄弟选择器和一般兄弟选择器的区别:
    相邻兄弟选择器获取的是紧挨着brother的young brother
    兄弟选择器会获取brother下所有的young brother,选择的范围更广

    ******注意:相邻兄弟选择器和一般兄弟选择器所选择到的元素,必须在同一个父元素下
    示例
    相邻兄弟选择器:


    图片.png

    一般兄弟选择器:

    图片.png

    相关文章

      网友评论

          本文标题:jQuery选择器之层级选择器

          本文链接:https://www.haomeiwen.com/subject/oudabttx.html