jquery after append appendto three functions of the difference (GO)

Source: Internet
Author: User

1. After function definition and usage: After () method inserts the specified content after the selected element. Syntax: $ (selector). After (content) instance:

<script type= "Text/javascript" src= "/jquery/jquery.js" ></script>
<script type= "Text/javascript" >
$ (). Ready (function () {
$ ("button"). Click (function () {
$ ("span"). After ("<a href=" # ">ddddd</a>")

})
})
</script>

<body>
<span>aaaaaaaaaaaaaaa</span>
<button>after functions </button>
</body>

The results are as follows:

<span>aaaaaaaaaaaaaaa</span>
<a href= "#" >ddddd</a>

The span tag has one more a tag behind it.

2. Append function definition and usage: the Append () method inserts the specified content at the end of the selected element (still inside). Syntax: $ (selector). Append ( contentInstance

<script type= "Text/javascript" src= "/jquery/jquery.js" ></script>
<script type= "Text/javascript" >
$ (). Ready (function () {
$ ("button"). Click (function () {
$ ("span"). Append ("<a href=" # ">ddddd</a>")

})
})
</script>

<body>
<span>aaaaaaaaaaaaaaa</span>
<button>after functions </button>
</body>


The results are as follows:

<span>aaaaaaaaaaaaaaa<a href= "#" >ddddd</a></span>
More than one a tag inside the span tag

3. appendTo function definition and usage: the AppendTo () method inserts the specified content at the end of the selected element (still inside). Syntax: $ ( content). AppendTo ( selectorInstance

<script type= "Text/javascript" src= "/jquery/jquery.js" ></script>
<script type= "Text/javascript" >
$ (). Ready (function () {
$ ("button"). Click (function () {
$ ("span"). AppendTo ("<a href=" # ">ddddd</a>"), so the wording is incorrect

$ ("<a href=" # ">ddddd</a>"). AppendTo ("span")

})
})
</script>

<body>
<span>aaaaaaaaaaaaaaa</span>
<button>after functions </button>
</body>


The results are as follows:

<span>aaaaaaaaaaaaaaa<a href= "#" >ddddd</a></span>
More than one a tag inside the span tag

The effect is the same as the APPEND function, except that they are written in the opposite way.

Note: The Before function, in contrast to the after function, indicates that the element is preceded by the specified element

jquery after append appendto three functions of the difference (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.