JQuery-document processing 1append-appendTo-prepend-prependTo-after-before application, jqueryappendto

Source: Internet
Author: User

JQuery-document processing 1append-appendTo-prepend-prependTo-after-before application, jqueryappendto

<! Doctype html> 


Differences between event processing in jquery documents

Append () adds content to the matching element.
AppendTo () adds content to the matched element.
Before () inserts content before each matching element.
InsertAfter () inserts matching elements to the end of another specified Element Set.
InsertBefore () inserts matched elements in front of another specified Element Set.
Prepend () is used to forward content to each matching element.
PrependTo () is used to forward content to each matching element.

Jquery Document Processing

W3school's brief explanation of jQuery. append (Function function (index, html:

Specifies the function to be inserted. The index is the index position of the receiving selector. Html is the current HTML of the receiving selector.

However, I think the code is more intuitive:

<Script type = "text/javascript"> $ (function () {// search for all divs $ ("div "). append (function (index, html) {// judge switch (index) {// append "degree" word after the first (0) div case 0 based on index: html + = "degree"; break; // The second (1) append "" word behind the div case 1: html + = ""; break; // append "tiger" behind the third (2) div case 2: html + = "tiger"; break ;} // set HTML certificate (this).html (html );});}); </script> <div> Bai </div> <div> Gu </div> <div> ya </div>
After the code is run, the result is

<Div> Baidu </div> <div> Google </div> <div> Yahoo </div>

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.