Course Content
AJAX and jQuery Plugins
Learn how to use AJAX and plugins with jQuery to create dynamic and interactive web applications.
0/3
JQuery
About Lesson

Adding, Removing, and Modifying Elements

  1. .append(): Adds content at the end of the selected element.
  2. .prepend(): Adds content at the beginning of the selected element.
  3. .after(): Adds content after the selected element.
  4. .before(): Adds content before the selected element.
JavaScript
$("#list").append("<li>Appended Item</li>");
$("#list").prepend("<li>Prepended Item</li>");
$("#list").after("<p>Content added after the list</p>");
$("#list").before("<p>Content added before the list</p>");
  1. .remove(): Removes the element along with its children.
  2. .empty(): Clears the content of the element but keeps the element itself.
JavaScript
$("#item1").remove(); // Removes a specific item
$("#list").empty(); // Clears the list but keeps the <ul>
  1. .clone(): Creates a copy of the selected element.
JavaScript
const clonedItem = $("#item1").clone();
$("#list").append(clonedItem);