Skip to content

Append DOM before last sibling

Using jQuery, you can append DOM (for example another sibling) before the last sibling with the following code:

<ul id="list">
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
  <li>Last Item</li>
$("#list li:last").before('<li>Second last item</li>');


Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.