jQuery append to bottom of list

Kmack picture Kmack · Jun 13, 2011 · Viewed 25.4k times · Source

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 PLANNING 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>");

Answer

Darin Dimitrov picture Darin Dimitrov · Jun 13, 2011

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'
        })
    })
);