Home  >  Article  >  Web Front-end  >  How to use jQuery append() method

How to use jQuery append() method

青灯夜游
青灯夜游Original
2021-07-02 14:58:4019273browse

In jQuery, the append() method can be used to insert specified content to the "end" inside the selected element; the syntax format "$(A).append(B)" means to go inside the A element Insert B content (can include HTML tags) at the end.

How to use jQuery append() method

The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.

The append() method inserts the specified content at the end (still inside) of the selected element.

Syntax:

$(A).append(B)

$(A).append(B) means inserting B (can include HTML tags) at the end of A.

The following is a code example to see how to use the append() method.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
        p{background-color:orange;}
    </style>
    <script src="js/jquery-1.10.0.min.js"></script>
    <script>
        $(function () {
            $("#btn").click(function () {
                var $strong = "<strong>--jQuery教程</strong>";
                $("p").append($strong);
            })
        })
    </script>
</head>
<body>
    <p>php中文网</p>
    <input id="btn" type="button" value="插入"/>
</body>
</html>

Rendering:

How to use jQuery append() method

After we click the [Insert] button, the HTML structure we get is as follows:

<p>php中文网<strong>--jQuery教程</strong></p>

For more programming-related knowledge, please visit: Introduction to Programming! !

The above is the detailed content of How to use jQuery append() method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn