.prependTo()
Syntax
.prependTo(target)
Parameters
target
- A selector, element, HTML string, or jQuery object; the matched set of elements will be inserted at the beginning of the selected element(s)
Return value
The jQuery object, for chaining purposes.
Description
Insert every element in the set of matched elements at the beginning 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>
We can create content and insert it into several elements.
$('<p>Test</p>').prependTo('.inner');
The result:
<h2>Header</h2>
<div class="container">
<div class="inner">
<p>Test</p>
Hello
</div>
<div class="inner">
<p>Test</p>
InnerText
</div>
</div>
select an element on the page and insert it into another.
$('h2').prependTo($('.container'));
If an element selected this way is inserted elsewhere, it will be moved into the target not cloned.
<div class="container">
<h2>Header</h2>
<div class="inner">Hello</div>
<div class="inner">InnerText</div>
</div>
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()