jquery append before final element
I have html structured like so.
<div id='container'>
<div class='item'> ... </div>
<div class='item'> ... </div>
<div class='item'> ... </div>
...
<div id='item_final'><input type="button" id='addOne'>...</div>
</div>
and what I am trying to do it add another item to the container class before the ite开发者_运维问答m_final div. The items are dynamic, so the number of them is unkown.
$('#container div:last').before( $('<div>') );
Try the .insertBefore method.
$('<div>').insertBefore('#item_final');
精彩评论