zoukankan      html  css  js  c++  java
  • jquery里互为逆过程的方法

    jquery里互为逆过程的方法reverse

    在jquery里,有不少互为逆过程的方法,如parent()与children(),parents()与find(),first()和last()等,这些联合起来有助于理解。

    一 children()和parent()

      这是一对遍历dom的jquery方法,这两个方法只查找元素的上一级或者下一级,接受selector参数。不会继续向上或者向下查找。eg:

    html:

    <div>grandfather
      <div>parent
        <div id='self'>self
          <div id="this">this</div>       
    <div>children          <div>descendants
                <span>a span</span>           
    </div>         </div>       </div>     </div> </div>
    $('#self').children("div")//只会选到children不会选到descendants元素
    $('#self').parent("div")//只会选到parent,不会选到grandfather元素

    二 find()和parents()

    find()接受selector或element参数,parents()接受filter参数

    与上面的两个方法相反,find()和parents()会一直查找到dom文本节点和顶层元素为止,还以上面的结构为例

    $('#self').children("div")//会选到descendants元素
    $('#self').parent("div")//会选到grandfather元素

    三 add()和not()

    add()在jquery选择的列表里增加元素,not()减去元素

    $('#self').children("div").add("span")//将span元素添加到前面的列表之中
    $('#self').find("div").not('#this')//将id为this的元素移出列表
    

      

  • 相关阅读:
    iOS 单例(Singleton)总结 和第三库引用单例
    iOS OpenURL用法简介
    CGContextRef学习笔记
    iOS 绘图(虚线、椭圆)
    iPhone4s 7.0.3-4 TableView 数据越界 解决方案
    Android Media应用开发
    RTMP & HLS
    Debug tool 学习笔记
    video codec 学习笔记
    matplotlib和numpy 学习笔记
  • 原文地址:https://www.cnblogs.com/imgss/p/6012686.html
Copyright © 2011-2022 走看看