How to add a list-item at specific position

You have to use after() instead of append():

Description: Insert content, specified by the parameter, after each element in the set of matched elements.

$('#list li:eq(1)').after('<li>Position 3</li>');

The documentation of append() clearly says:

Insert content (…) to the end of each element.

For completeness:

Note that :eq(n) matches the nth element of the matching element set, whereas :nth-child(n) matches the nth child of the parent.

Leave a Comment