jquery prependTo() method


  Translation results:

prepend

UK[pri:'pend] US[pri:'pend]

vt. Consider in advance, plan in advance, plan in advance

to

英[tə] 美[tu,tə]

prep.To; toward; toward; about; belonging to

adv. Towards one direction; to a certain state; to close

jquery prependTo() methodsyntax

Function: prependTo() method inserts the specified content at the beginning of the selected element (still inside). The prepend() and prependTo() methods have the same effect. The difference is in the syntax: the placement of content and selectors, and the ability to use the prepend() function to insert content.

Syntax: $(content).prependTo(selector)

Parameters:

##

jquery prependTo() methodexample

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".btn1").click(function(){
    $("<b>Hello World!</b>").prependTo("p");
  });
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button class="btn1">在每个 p 元素的开头插入文本</button>
</body>
</html
Run instance »

Click the "Run instance" button to view the online instance

ParameterDescription
content Required. Specifies the content to be inserted (can include HTML tags).
selector Required. Specifies where content should be inserted.