Davide Fish Davide Fish - 1 year ago 100
HTML Question

jQuery last-child and insetBefore does not work

My code:

$('#discussion li:last-child').insertBefore('<li class="other">ciao</li>');

The above does not work. This erases the last

I wish it add another
after the last

Here's a complete example

Answer Source

See this

    $('<li class="other">ciao</li>').insertAfter("#discussion li:last-child");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<ol id="discussion">
    <li class="self">ciao</li>
<button id="bott">click</button>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download