I\'d like to add a at a specific position, for example:
- Position 1
- Posi
Check insertAfter
here
$('<option val="position3">Position3</option>').insertAfter('#list :nth-child(<give childnumber here>)')
index start with 1
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 n
th element of the matching element set, whereas :nth-child(n) matches the n
th child of the parent.
You should use after()
or insertAfter()
http://api.jquery.com/category/manipulation/dom-insertion-outside/