最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin5浏览0评论

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>');
发布评论

评论列表(0)

  1. 暂无评论