Home > Web Front-end > JS Tutorial > How Can I Use appendTo() and prependTo() to Move HTML Elements?

How Can I Use appendTo() and prependTo() to Move HTML Elements?

DDD
Release: 2024-12-06 08:15:16
Original
623 people have browsed it

How Can I Use appendTo() and prependTo() to Move HTML Elements?

Moving an Element Within Another Element in HTML

To move one DIV element inside another, use either the appendTo or prependTo functions.

appendTo:

This function appends the source element to the end of the destination element.

$("#source").appendTo("#destination");
Copy after login

prependTo:

This function adds the source element to the beginning of the destination element.

$("#source").prependTo("#destination");
Copy after login

Example:

<div>
Copy after login
Copy after login

JavaScript:

$("#appendTo").click(function() {
  $("#moveMeIntoMain").appendTo($("#main"));
});
$("#prependTo").click(function() {
  $("#moveMeIntoMain").prependTo($("#main"));
});
Copy after login

HTML:

<div>
Copy after login
Copy after login

The above is the detailed content of How Can I Use appendTo() and prependTo() to Move HTML Elements?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template