jQuery - end() 方法



描述

end() 方法會撤銷最近的破壞性操作,將匹配元素集更改回破壞性操作之前的狀態。

語法

以下是使用此方法的簡單語法:

operations.end( )

引數

以下是此方法使用到的所有引數的描述:

示例

以下是一個簡單的示例,展示了此方法的用法。它選擇所有段落,查詢這些段落內的 span 元素,然後將選擇恢復到段落。

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://tutorialspoint.tw/jquery/jquery-3.6.0.js">
      </script>
		
      <script>
         $(document).ready(function(){
            $("p").find("span").end().css("border", "2px red solid");
         });
      </script>
		
      <style>
         p{ 
            margin:10px; 
            padding:10px; 
         }
      </style>
   </head>
	
   <body>
      <p><span>Hello</span>, how are you?</p>
   </body>
</html>

這將產生以下結果:

jquery-traversing.htm
廣告
© . All rights reserved.