</>
Skip to content
jQuery lessons (18/39)

jQuery — Add Elements

append()

Add content inside (at the end):

$("ul").append("<li>New item</li>");

appendTo()

$("<li>New item</li>").appendTo("ul");

prepend()

Add content inside (at the beginning):

$("ul").prepend("<li>First item</li>");

prependTo()

$("<li>First item</li>").prependTo("ul");

after()

Add content after the element:

$("p").after("<p>New paragraph</p>");

before()

Add content before the element:

$("p").before("<p>Previous paragraph</p>");

Insert Multiple Elements

$("ul").append("<li>A</li><li>B</li><li>C</li>");

Append Content from Variable

var newItem = $("<li>").text("Dynamic item");
$("ul").append(newItem);

Insertion Methods Summary

MethodPosition
append()Inside, at end
prepend()Inside, at start
after()After element
before()Before element

Mini Practice

  1. Append a new list item
  2. Prepend a heading to a section
  3. Add an element after another
  4. Create and append an element dynamically

Up Next

Continue with Remove Elements — deleting content from the DOM.

Related Topics

Frequently Asked Questions about Add Elements

What is Add Elements in jQuery?

Add Elements is a fundamental concept in jQuery. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Add Elements?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Add Elements.

Why is Add Elements important in jQuery?

Add Elements is essential for jQuery development. Understanding this concept will help you write better code and solve real-world problems more effectively.