jQuery insert div as certain index

后端 未结 9 694
眼角桃花
眼角桃花 2020-12-07 19:38

Say I have this:

1
2

bu

9条回答
  •  失恋的感觉
    2020-12-07 20:36

    Use my simple plugin Append With Index :

    $.fn.appendToWithIndex=function(to,index){
            if(! to instanceof jQuery){
                to=$(to);
            };
            if(index===0){
                $(this).prependTo(to)
            }else{
                $(this).insertAfter(to.children().eq(index-1));
            }
        };*
    

    Now :

    $('
  • fgdf
  • ').appendToWithIndex($('ul'),4)

    Or :

    $('
  • fgdf
  • ').appendToWithIndex('ul',0)

提交回复
热议问题