Introduction:

In this article we will explain how to add specified content at the end of the selected element in jQuery or What is append() method in jQuery or why use append() method in jQuery with example.

Description:

The jQuery append() method is used to add specified content end of  the selected element. If you want to add content at the beginning of the selected element, you should use jQuery prepend () method.

Syntax:

$(selector).append(“content”);

Let’s see, Example of jQuery append() method

<!DOCTYPE html>
<html>
<head>
    <title>Example of jQuery append method</title>
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script>
        $(document).ready(function () {
            $("#btntext").click(function () {
                $("p").append("<b>for beginners and experienced Developers.</b>.");
            });
            $("#btnitem").click(function () {
                $("ul").append("<li><b>Desktop</b></li>");
            });
        });
    </script>
</head>
<body>
    <p>This is a tutorial website.</p>
    <ul>
        <li>Computer</li>
        <li>Laptop</li>
    </ul>
    <button id="btntext">Append text</button>
    <button id="btnitem">Append item</button>
</body>
</html>


 Let's check live example

comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like