Thursday, December 11, 2025
HomeLanguagesJavascriptjQuery appendTo() Method

jQuery appendTo() Method

The appendTo() method is an inbuilt method in jQuery that is used to insert HTML element at the end of the selected element. 

Syntax:

$(content).appendTo(selector)

Here the element content specifies the content to be inserted. 

Parameters: It accepts a parameters “selector” that specifies the elements to which content will be appended.

 Return Value: It returns the modified selected element.

Example 1: In this example, id content with the element “span” will be appended to the id “#hel” element. 

HTML




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
    <script src=
    </script>
    <style>
        #hel {
            background: lightgreen;
            display: block;
            border: 2px solid green;
            padding: 10px;
            width: 300px;
        }
    </style>
</head>
  
<body>
    <span>neveropen Writer !!!</span>
    <div id="hel">Hello- </div>
    <script>
        $("span").appendTo("#hel"); 
    </script>
</body>
  
</html>


Output: 

 

Example 2: In the below example, we are directly appending a “p” element using this method. 

HTML




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
      <script src=
    </script>
    <style>
        body {
            display: block;
            width: 250px;
            height: 100px;
            border: 2px solid green;
            padding: 10px;
        }
    </style>
</head>
  
<body>
    <h2>Greetings from gfg !</h2>
    <div class="container">
        <div class="inner">
            Hello
        </div>
    </div>
    <script>
        $("<p>Everyone !!!</p>").appendTo(".inner"); 
    </script>
</body>
  
</html>


Output: 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32440 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6811 POSTS0 COMMENTS
Nicole Veronica
11950 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12023 POSTS0 COMMENTS
Shaida Kate Naidoo
6943 POSTS0 COMMENTS
Ted Musemwa
7193 POSTS0 COMMENTS
Thapelo Manthata
6889 POSTS0 COMMENTS
Umr Jansen
6880 POSTS0 COMMENTS