jQuery 中的 Insertafter方法函数

首页 / jQuery入门教程 / jQuery 中的 Insertafter方法函数

insert After(selector)方法将所有匹配的元素插入到另一个指定的元素集之后。

Insertafter - 语法

selector.insertAfter( selector )

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

  • selector    -  内容,在该内容之后插入所选元素。

Insertafter - 示例

<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").click(function () {
               $("#source").insertAfter(this);
            });
         });
      </script>
		
      <style>
         .div{ margin:10px;padding:12px; border:2px solid #666; width:60px;}
      </style>
   </head>
	
   <body>
      <p>Click on any square below to see the result:</p>
		
      <div class="div" id="source"></div>
      <div class="div" style="background-color:blue;"></div>
      <div class="div" style="background-color:green;"></div>
      <div class="div" style="background-color:red;"></div>
   </body>
</html>

这将产生以下输出-

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/dom-insertafter.html

来源:LearnFk无涯教程网

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Android开发高手课 -〔张绍文〕

即时消息技术剖析与实战 -〔袁武林〕

数据中台实战课 -〔郭忆〕

Vim 实用技巧必知必会 -〔吴咏炜〕

MySQL 必知必会 -〔朱晓峰〕

说透数字化转型 -〔付晓岩〕

手把手带你搭建秒杀系统 -〔佘志东〕

云时代的JVM原理与实战 -〔康杨〕

Midjourney入门实践课 -〔Jovi〕

好记忆不如烂笔头。留下您的足迹吧 :)