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>