append,appendTo和prepend #1daae2

1.append(content)                                                                                        

Additional content to match the interior of each element.

1 <div>
2 <p name="p1">p1</p>
3 </div>

To re-add such as a div p Tags:

. $ ( 'Div') append ( '<p name = "p2"> p2 </ p>'); // results:

<div>
<p name="p1">p1</p>
<p name="p2">p2</p>
</div>

2.appendTO(content)                                                                  

All the elements that match elements of another element is added to the collection of specified.

To achieve the desired effect () in the append, the code is as follows: $ ( '<p name = "p2"> </ p>') appendTo ( 'div')..

 

3.prepend(content)                                                                    
Internal head content to match each element.

This is the best way to insert the contents of all matched elements inside the start.

prepend(function(index, html))

Returns an HTML string, a match is appended to each element inside. Accepts two parameters, index parameter index value for the object in this collection, html parameters for this object is the original html value.

例1效果:$('div').prepend(function(0,'<p name="p2">p2</p>'));

Summary: append (), appendTo () and The prepend () within the tag are additional matching elements, except that: append () and the appendTo () elements are added in the back, and The prepend () is the top element added.

Reproduced in: https: //www.cnblogs.com/Codenewbie/p/3436152.html

Guess you like

Origin blog.csdn.net/weixin_33995481/article/details/93448198