• $("ul").append(li_1); // 内部添加并且放到内部的最后面
  • $("ul").prepend(li_2); // 内部添加并且放到内部的最前面
  • });
  • script>
  • html>
  • 🔗外部添加 

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <title>ajax studytitle>
    6. <script src="https://code.jquery.com/jquery-3.6.1.min.js">script>
    7. head>
    8. <style>
    9. div {
    10. font-weight: bold;
    11. }
    12. style>
    13. <body>
    14. <div class="box1">原始divdiv>
    15. body>
    16. <script>
    17. $(function () {
    18. var div_1 = $("
      我是before添加的div
      "
      ); // 创建元素2
    19. var div_2 = $("
      我是after添加的div
      "
      ); // 创建元素1
    20. $(".box1").before(div_1); // 内部添加并且放到内部的最前面
    21. $(".box1").after(div_2); // 内部添加并且放到内部的最后面
    22. });
    23. script>
    24. html>

    🧩删除元素

    1️⃣empty()方法

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <title>ajax studytitle>
    6. <script src="https://code.jquery.com/jquery-3.6.1.min.js">script>
    7. head>
    8. <style>
    9. ul {
    10. background-color: yellow;
    11. height: 60px;
    12. }
    13. style>
    14. <body>
    15. <ul>
    16. <li>1li>
    17. <li>2li>
    18. <li>3li>
    19. ul>
    20. <button>点击删除button>
    21. body>
    22. <script>
    23. $("button").click(function () {
    24. $("ul").empty();
    25. console.log($("ul").html());
    26. });
    27. script>
    28. html>

    2️⃣remove()方法

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <title>ajax studytitle>
    6. <script src="https://code.jquery.com/jquery-3.6.1.min.js">script>
    7. head>
    8. <style>
    9. ul {
    10. background-color: yellow;
    11. height: 60px;
    12. }
    13. style>
    14. <body>
    15. <ul>
    16. <li>1li>
    17. <li>2li>
    18. <li>3li>
    19. ul>
    20. <button>点击删除button>
    21. body>
    22. <script>
    23. $("button").click(function () {
    24. $("ul").remove();
    25. console.log($("ul").html());
    26. });
    27. script>
    28. html>

    📚持续更新🔥

  • 相关阅读:
    幽默直观的文档作者注释
    服务端(后端)主动通知前端的实现:WebSocket(springboot中使用WebSocket案例)
    【Python】-- 列表list(基本语法、常用方法)
    神经网络深度学习(五)初始化
    【数据结构】前缀树Trie
    【揭秘Vue】nextTick的神秘面纱:原理与作用一览无余!
    [acwing周赛复盘] 第 60 场周赛20220716
    vue路由切换时,若是一个路径但是参数不同,页面不会变化
    00. 这里整理了最全的爬虫框架(Java + Python)
    【Firewall】服务器访问限制白名单
  • 原文地址:https://blog.csdn.net/weixin_53231455/article/details/128057087