Examples of appendTo () method usage in jQuery, jqueryappendto
This document describes the appendTo () method in jQuery. Share it with you for your reference. The specific analysis is as follows:
This method inserts the matched element into the end of the specified element, and the insert position is inside the element.
The appendTo () method has the same functions as the append () method, but its syntax is different, although its form is the same.
Syntax structure:
Copy codeThe Code is as follows: $ (selector). appendTo (content)
Parameter List:
Parameters |
Description |
Selector |
The matching element to be inserted. |
Content |
Element to be inserted with matching elements. |
Instance code:
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> appendTo () function-helper's house </title>
<Style type = "text/css">
P {
Height: 100px;
Width: 100px;
Border: 1px solid blue;
}
Div {
Height: 200px;
Width: 200px;
Border: 1px solid green;
}
</Style>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Button"). click (function (){
$ ("P"). appendTo ("div ");
})
})
</Script>
</Head>
<Body>
<P> I am the content of p </p>
<Div> I am a div </div>
<Button> click to view results </button>
</Body>
</Html>
In the above Code, when you click the button, you can move the p element to the internal tail of the div element.
I hope this article will help you with jQuery programming.