jquery - How to add <li> using javascript? - Stack Overflow

I want to add one more li at last but using JavaScriptjQueryfor example i want to add this li at last

I want to add one more li at last but using JavaScript/jQuery

for example i want to add this li at last <li><a href="#header" >Back to top</a></li>

<ul id="nav">
    <li><a href="#nowhere" >Lorem</a></li>
    <li><a href="#nowhere" >Aliquam</a></li>
    <li><a href="#nowhere" >Morbi</a></li>
    <li><a href="#nowhere" >Praesent</a></li>
    <li><a href="#nowhere" >Pellentesque</a></li>
        Here i want to add one more li using javascript
</ul>

I want to add one more li at last but using JavaScript/jQuery

for example i want to add this li at last <li><a href="#header" >Back to top</a></li>

<ul id="nav">
    <li><a href="#nowhere" >Lorem</a></li>
    <li><a href="#nowhere" >Aliquam</a></li>
    <li><a href="#nowhere" >Morbi</a></li>
    <li><a href="#nowhere" >Praesent</a></li>
    <li><a href="#nowhere" >Pellentesque</a></li>
        Here i want to add one more li using javascript
</ul>
Share Improve this question asked May 27, 2010 at 5:16 Jitendra VyasJitendra Vyas 153k240 gold badges587 silver badges868 bronze badges 1
  • possible duplicate of jQuery: how to add <li> in an existing <ul>? – Jørn Schou-Rode Commented May 27, 2010 at 22:54
Add a ment  | 

2 Answers 2

Reset to default 4
$(document).ready( function(){
    $('ul#nav').append('<li><a href="#header">Back to top</a></li>');
}  

Use the append function.

$("#nav").append('<li><a href="#header">Back to top</a></li>');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744072943a4553876.html

相关推荐

  • jquery - How to add &lt;li&gt; using javascript? - Stack Overflow

    I want to add one more li at last but using JavaScriptjQueryfor example i want to add this li at last

    9天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信