Detailed Description:
$ele. Append,. AppendTo,. prepend,. Prependto,. Before,. InsertBefore,. After,. InsertAfter,. ReplaceAll following these method calls, If the object being added is the original object on the page, when these methods are called, the original object disappears and appears in a new place (note: The object here is a jquery object)
Phenomenon:
Code:
<body> <ul> <li>num:1</li> <li>num:2</li> <li>num:3 </li> <li>num:4</li> <li>num:5</li> </ul> <script> var $li = $ ("<span>~~ label ~~</span>") $li. AppendTo ($ ("Li")); $ ("LI:GT (2)"). Append ($li); </script> </body>
Problem:
Why don't add two span tags behind NUM5
Reason:
$ele. Append, AppendTo, prepend, Prependto, before, InsertBefore, after, InsertAfter, ReplaceAll
If the object being added is the original object on the page, when these methods are called, the original object disappears and appears in a new place (note: The object here is a jquery object)
Workaround:
1. First line: Create label; second line: encapsulate the label as a jquery object and add it; the third line: Add the label directly to the corresponding jquery object var li = "<span>~~ label ~~</ Span> "; $ (LI). AppendTo ($ ("Li")); $ ("LI:GT (2)"). Append (li); 2. The first line: Create a jquery object, the second line: Add the object, and the third line: Reassign the value to $li, which is an object that is not displayed on the page (and therefore does not consider the problem of disappearing); line four: Add the re-assigned $li var $li = $ ("<span>~~ tag ~~</span>"); $li. AppendTo ($ ("Li")); = $ ("<span>~~ label ~~</span>"); $ ("LI:GT (2)"). Append ($li);
Append, AppendTo, prepend, Prependto, before, InsertBefore, after, InsertAfter, ReplaceAll methods are called, the elements that were originally displayed on the page disappear