$( ".inner" ).append( "<p>Test</p>" );
$( "body" ).append( $newdiv1, [ newdiv2, existingdiv1 ] );
$( "p" ).append( "<strong>Hello</strong>" );
$( "p" ).append( $( "strong" ) );
$( "p" ).append( document.createTextNode( "Hello" ) );
.appendTo(target) 把对象插入到目标元素尾部,目标元素可以是selector, DOM对象, HTML string, 元素集合,jQuery对象;
Insert every element in the set of matched elements to the end of the target.
复制代码 代码如下:
$( "h2" ).appendTo( $( ".container" ) );
$( "<p>Test</p>" ).appendTo( ".inner" );
.prepend(content[,content]) / .prepend(function(index,html)) 向对象头部追加内容,用法和append类似
Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.
复制代码 代码如下:
$( ".inner" ).prepend( "<p>Test</p>" );
.prependTo(target) 把对象插入到目标元素头部,用法和prepend类似
Insert every element in the set of matched elements to the beginning of the target.
复制代码 代码如下:
$( "<p>Test</p>" ).prependTo( ".inner" );
.before([content][,content]) / .before(function) 在对象前面(不是头部,而是外面,和对象并列同级)插入内容,参数和append类似
Insert content, specified by the parameter, before each element in the set of matched elements.
复制代码 代码如下: