开发者

jquery append before final element

开发者 https://www.devze.com 2023-01-09 20:42 出处:网络
I have html structured like so. <div id=\'container\'> <div class=\'item\'> ... </div>

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');
0

精彩评论

暂无评论...
验证码 换一张
取 消