jQuery siblings() 方法

jQuery 教程 · 2019-03-28 11:59:21

实例

返回带有类名 "start" 的每个 <li> 元素的所有同级元素:

$(document).ready(function(){
$("li.start").siblings().css({"color":"red","border":"2px solid red"});
});

结果:

    ul (parent)
  • li (sibling)
  • li (sibling)
  • li (sibling with class name "start")
  • li (sibling)
  • li (sibling)

定义和用法

siblings() 方法返回被选元素的所有同级元素。

同级元素是共享相同父元素的元素。

DOM 树:该方法沿着 DOM 元素的同级元素向前和向后遍历。

提示:请使用 prev() 或 next() 方法来缩小仅仅搜索前一个同级元素或后一个同级元素的范围。

语法

$(selector).siblings(filter)

参数 描述
filter 可选。规定缩小搜索同级元素范围的选择器表达式。

点击查看所有 jQuery 教程 文章: https://www.codercto.com/courses/l/35.html

查看所有标签

Data Structures and Algorithms in Java

Data Structures and Algorithms in Java

Michael T. Goodrich、Roberto Tamassia / Wiley / 2010-01-26 / USD 177.41

* This newest edition examines fundamental data structures by following a consistent object-oriented framework that builds intuition and analysis skills of data structures and algorithms * Presents ne......一起来看看 《Data Structures and Algorithms in Java》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

MD5 加密
MD5 加密

MD5 加密工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具