Description: Get the ancestors of each element in the current set of matched elements, up to but not including the element matched by the selector, DOM node, or jQuery object.

获得当前匹配元素集合中每个元素的祖先元素,直到(但不包括)被选择器、DOM 节点或 jQuery 对象匹配的元素。

.parentsUntil( [selector] [, filter] )

.parentsUntil( [element] [, filter] )

Given a selector expression that represents a set of DOM elements, the .parentsUntil() method traverses through the ancestors of these elements until it reaches an element matched by the selector passed in the method's argument. The resulting jQuery object contains all of the ancestors up to but not including the one matched by the .parentsUntil() selector.

If the selector is not matched or is not supplied, all ancestors will be selected; in these cases it selects the same elements as the .parents() method does when no selector is provided.

Example:

<ul class="level-1 yes">
<li class="item-i">I</li>
<li class="item-ii">II
<ul class="level-2 yes">
<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-a").parentsUntil(".level-1")
.css(
"background-color", "red");

$(
"li.item-2").parentsUntil( $("ul.level-1"), ".yes" )
.css(
"border", "3px solid green");

</script>

中文文档:http://www.w3school.com.cn/jquery/traversing_parentsuntil.asp

相关的还有:nextUtiljQuery 参考手册 - 遍历

更多相关文章

  1. Jquery对选取到的元素显示指定的长度,对于的字符串用“...”显示
  2. jQuery编程基础精华02(属性、表单过滤器,元素的each,表单选择器,子元
  3. scrollTop到溢出滚动div中的活动元素
  4. jQuery使用之(四)处理页面的表单元素
  5. jQuery在点击按钮上迭代/循环遍历数据表
  6. jQuery入门(2) 获取元素和DOM转换
  7. 用Jquery控制元素的上下移动 实现排序功能
  8. jQuery -添加活动类并在单击时从其他元素中删除活动类
  9. 仅当鼠标停留在元素上时,jQuery才会激活鼠标悬停函数

随机推荐

  1. 跟我学Android NDK开发(一)
  2. android progressbar style定义解析
  3. android 设置支持pad等大屏幕、大分辨率
  4. Android开发——控件基础(三)EditText组件
  5. Android开发你需要具备的基本功
  6. 空闲时间玩玩Andriod,你知道如何配置环境
  7. AndroidStudio安装教程(Windows环境下)
  8. android文字阴影效果设置
  9. 原生态Android操作介绍之一
  10. android 布局 px or dip