Open In App

How to append a jQuery object to all paragraphs using jQuery ?

In this article, we will see how to append a jQuery object to all paragraphs using jQuery. Append means we add something to an existing element. The object is used to define a container for an external resource like a page, a picture, a media player, or a plug-in application.

Used Methods:



Approach: 

Example: In this example, we are using the above-explained approach.






<!DOCTYPE html>
<html>
<head>
    <script src=
    </script>
    <style>
        body {
            text-align: center;
            font-size: 20px;
        }
 
        button {
            background-color: #4CAF50;
            /* Green */
            border: none;
            color: white;
            padding: 15px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
        }
 
        object {
            font-size: 30px;
            color: lightgreen;
            background-color: green;
        }
    </style>
    <script>
        $(document).ready(function () {
            $("button").click(function () {
                $("p").append(
                    "<object>This is object</object>.");
            });
        });
    </script>
</head>
 
<body>
    <h2 style="color:green">GeeksforGeeks</h2>
    <b>
        Click on the button to append object
        at the end of every paragraph.
    </b>
 
    <p>This is a paragraph.</p>
 
    <p>This is another paragraph.</p>
 
    <button>Append Object</button>
</body>
</html>

Output:

Append object


Article Tags :