Are you first timer at lazacode.org? Why not join us and start exchange your knowledge with everyone. Register today!

jQuery .append() .appendTo() method

0 votes
2 views
added Mar 20 in jQuery by LC Marshal Second Warrant Officer (6,690 points)
edited Apr 2 by LC Marshal

.appendTo( target ) - Insert every element in the set of matched elements to the end of the target.

The .append() and .appendTo() methods perform the same task. The major difference is in the syntax-specifically, in the placement of the content and target. With .append(), the selector expression preceding the method is the container into which the content is inserted. With .appendTo(), on the other hand, the content precedes the method, either as a selector expression or as markup created on the fly, and it is inserted into the target container. src: http://api.jquery.com/appendto/

Example

Find .content and hide it first prior insert or add it to the end of #mylastdiv

$('.content').hide();
$('.content').appendTo("#mycontent").fadeIn(1000);

1 Example

0 votes
responded Apr 13 by LC Marshal Second Warrant Officer (6,690 points)

Find .submitted and insert it under h1.page-header (in its class)

$('span.submitted').appendTo('h1.page-header').fadeIn(400);

 

Find .submitted and insert it before h1.page-header (in its class)

$('span.submitted').prependTo('h1.page-header').fadeIn(400);
lazacode.org - Malaysia based Knowledge Exchange Platform, where you can share your finding or solution with other members of community.
...