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");
prependTo:
This function adds the source element to the beginning of the destination element.
$("#source").prependTo("#destination");
Example:
<div>
JavaScript:
$("#appendTo").click(function() { $("#moveMeIntoMain").appendTo($("#main")); }); $("#prependTo").click(function() { $("#moveMeIntoMain").prependTo($("#main")); });
HTML:
<div>
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!