• append() - 在被选元素的结尾插入内容
    • prepend() - 在被选元素的开头插入内容
    • after() - 在被选元素之后插入内容
    • before() - 在被选元素之前插入内容

    隐藏与显示.gif

    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <script src="/jquery/jquery-3.6.0.js">
    5. </script>
    6. <script>
    7. $(document).ready(function () {
    8. $("#btn1").click(function () {
    9. $("p").append(" <b>哈哈哈</b>.");
    10. });
    11. $("#btn2").click(function () {
    12. $("ol").append("<li>你好</li>");
    13. });
    14. });
    15. </script>
    16. </head>
    17. <body>
    18. <p>This is a paragraph.</p>
    19. <p>This is another paragraph.</p>
    20. <ol>
    21. <li>List item 1</li>
    22. <li>List item 2</li>
    23. <li>List item 3</li>
    24. </ol>
    25. <button id="btn1">追加文本</button>
    26. <button id="btn2">追加列表项</button>
    27. </body>
    28. </html>