当前位置: 首页 > 文档资料 > jQuery 入门教程 >

prevAll([selector] )

优质
小牛编辑
111浏览
2023-12-01

描述 (Description)

prevAll( [selector] )方法查找当前元素前面的所有兄弟元素。

语法 (Syntax)

以下是使用此方法的简单语法 -

<i>selector</i>.prevAll( [selector] )

参数 (Parameters)

以下是此方法使用的所有参数的说明 -

  • selector - 这是可选的选择器,用于过滤以前的Elements。

例子 (Example)

以下是一个简单的例子,简单地显示了这种方法的用法 -

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function(){
            $("div:last").prevAll().addClass("hilight");
         });
      </script>
      <style>
         .hilight { background:yellow; }
      </style>
   </head>
   <body>
      <div>first</div>
      <div>sibling<div>child</div></div>
      <div>sibling</div>
      <div>sibling</div>
   </body>
</html>

例子 (Example)

以下是一个简单的例子,简单地显示了这种方法的用法 -

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function(){
            $("div:last").prevAll().addClass("hilight");
         });
      </script>
      <style>
         .hilight { background:yellow; }
      </style>
   </head>
   <body>
      <div class = "hilight">first</div>
      <div class = "hilight">sibling<div>child</div></div>
      <div class = "hilight">sibling</div>
      <div>sibling</div>
   </body>
</html>