How to add a list item to an existing unordered list

This would do it:

$("#header ul").append('<li><a href="https://stackoverflow.com/user/messages"><span class="tab">Message Center</span></a></li>');

Two things:

  • You can just append the <li> to the <ul> itself.
  • You need to use the opposite type of quotes than what you’re using in your HTML. So since you’re using double quotes in your attributes, surround the code with single quotes.

Leave a Comment