How to use jquery to insert a new LI element after any of the specified LI elements:
This section describes how to use the jquery implementation to insert a new LI element behind any Li element.
Native JavaScript can use the InsertBefore () function, which can be found in the InsertBefore, InsertAfter, and AppendChild sections of JavaScript .
Here's how to implement this with jquery.
code example:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Ant Tribe</title><styletype= "Text/css">ul Li{Height:25px;List-style:None;font-size:12px;}</style><Scriptsrc= "Http://libs.baidu.com/jquery/1.9.0/jquery.js"></Script><Scripttype= "Text/javascript">$ (document). Ready (function(){ $("#bt"). Click (function(){ $("#box Li"). EQ (1). After ("The spirit of <li> sharing and the bosom of mutual help are the most important source of progress. </li>"); $( This). Prop ("Disabled",true); })})</Script> </Head> <Body> <ulID= "box"> <Li>Ant Tribe welcomes You</Li> <Li>Provides a rich div CSS tutorial content.</Li> <Li>Only hard work will have a good future.</Li></ul><inputtype= "button"ID= "BT"value= "View Effect"/></Body> </HTML>
The above code implements our requirements by clicking the button to add a new LI element to the back of the second Li element.
Related reading:
The 1.eq () function can be found in the section on the EQ () method of jquery .
The 2.after () function can be found in the After () method section of jquery .
The 3.prop () function can be found in the prop () method section of jquery .
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=15190
For more information, refer to: http://www.softwhy.com/jquery/
How to use jquery to insert a new LI element behind any of the specified LI elements