开发者

jQuery append to bottom of list

Can someone lend me a hand

I have this unordered list

<ul id="nav">
<li><a href="whatwedo.aspx">WHAT WE DO</a>
<ul>
    <li><a href="development.aspx">Development</a></li>
    <li><a href="marketassessment.aspx">MARKET ASSESSMENT AND CONCEPT DEVELOPMENT</a></li>
    <li><a href="planning.aspx">DEVELOPMENT PLANNIN开发者_开发百科G AND OVERSIGHT</a></li>
    <li><a href="preopening.aspx">PRE-OPENING OPERATIONAL SERVICES</a></li>
    <li><a href="operations.aspx">OPERATIONAL MANAGEMENT SERVICES</a></li>
    <li><a href="turnaround.aspx">TURNAROUND SERVICES</a></li>
    <li><a href="news.aspx">NEWS</a></li>
</ul>
</li>
<li><a href="ourparks.aspx">OUR PARKS</a></li>
<li><a href="contact.aspx">CONTACT US</a></li> </ul>

And I want to add a new list to the bottom of the list.

<li class="last_link"><a href="https://projects.parc-services.com" target="blank">Login</a></li>

Would I go about it by doing something like this?

$("#nav ul").prepend("<li></li>");


If you want to add at the end use the append() method instead of prepend():

$('#nav ul').append('<li class="last_link"><a href="https://projects.parc-services.com" target="blank">Login</a></li>');

or as I prefer:

$('#nav ul').append(
    $('<li/>', {
        'class': 'last_link',
        html: $('<a/>', {
            href: 'https://projects.parc-services.com',
            target: '_blank',
            text: 'Login'
        })
    })
);


prepend adds something at the beginning of an element. append is used to add something at the end.

$("#nav ul").append($("<li></li>").html('something'));

And if you want to add a class, or anything else you can:

$("#nav ul").append($("<li></li>").html('something')
                                  .addClass('myclass'));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜