.appendTo()
Syntax
.appendTo(target)
Parameters
target:
- A selector, element, HTML string, or jQuery object; the matched elements will be inserted at the end of the element(s) specified by this parameter
Return value
The jQuery object, for chaining purposes.
Description
Insert every element in the set of matched elements at the end of the target.
Examples
Consider the following HTML code:
<h2>Header</h2>
<div class="container">
<div class="inner">Hello</div>
<div class="inner">InnerText</div>
</div>
$('<p>Test</p>').appendTo('.inner');
The result:
<h2>Header</h2>
<div class="container">
<div class="inner">
Hello
<p>Test</p>
</div>
<div class="inner">
InnerText
<p>Test</p>
</div>
</div>
Select an element on the page and insert it into another.
$('h2').append($('.container'));
If an element selected is inserted some where else, it will be moved into the target not cloned.
<div class="container">
<div class="inner">Hello</div>
<div class="inner">InnerText</div>
<h2>Header</h2>
</div>
Add tag to body
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<style type="text/css">
.changeP { font-weight: bold; color:red;}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("<div><p>Hello</p></div>").appendTo("body")
});
</script>
</head>
<body>
<form>
<input type="radio" value="Option">
</form>
</body>
</html>
The reverse of $(A).append(B)
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").appendTo( $("b") );
});
</script>
<style>
.selected { color:blue; }
</style>
</head>
<body>
<body>
<b>asdf</b><p>asdf: </p>
</body>
</html>
Home
JavaScript Book
jQuery
JavaScript Book
jQuery
DOM:
- jQuery DOM
- $("html tags"):generate code with the jQuery wrapper function.
- .add()
- .addClass()
- .after()
- .andSelf()
- .append()
- .appendTo()
- .attr()
- .before()
- .children()
- .clone()
- .closest()
- .contents()
- .css()
- .detach()
- .filter()
- .first()
- .get()
- .has()
- .hasClass()
- .height()
- .html()
- .index()
- .innerHeight()
- .innerWidth()
- .insertAfter()
- .insertBefore()
- .is()
- .last()
- .map()
- .next()
- .nextAll()
- .nextUntil()
- .not()
- .offset()
- .offsetParent()
- .outerHeight()
- .outerWidth()
- .parent()
- .parents()
- .parentsUntil()
- .position()
- .prepend()
- .prependTo()
- .prev()
- .prevAll()
- .prevUntil()
- .remove()
- .removeClass()
- .removeAttr()
- .replaceAll()
- .replaceWith()
- .siblings()
- .scrollLeft()
- .scrollTop()
- .slice()
- .text()
- .toArray()
- .toggleClass()
- .unwrap()
- .val()
- .wrap()
- .wrapAll()
- .wrapInner()
- .width()