jQuery after() 方法


jQuery 中的 after() 方法用於在選定的元素後面插入指定內容。

示例

現在,我們來看一個實現 jQuery after() 方法的示例 −

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("#btndemo").click(function(){
         $("img").after("<strong>Text inserted after!</strong>");
      });
   });
</script>
</head>
<body>
<img src="https://tutorialspoint.tw/images/tp-logo-diamond.png" alt="Tutorialspoint Logo" width="220" height="120"><br><br>
<button id="btndemo">Insert specified content</button>
</body>
</html>

輸出

這會產生以下輸出 −

點選上面的按鈕顯示文字 −

更新於: 2019 年 11 月 11 日

187 次瀏覽

開啟您的 職業生涯

完成課程以獲得認證

立即開始
廣告