jquery reorder divs

前端 未结 4 584
旧巷少年郎
旧巷少年郎 2021-01-04 20:59

I have 3 divs want to reverse the order on doucment ready

First
Second
4条回答
  •  星月不相逢
    2021-01-04 21:39

    $(
       $("div[id|=block]")
          .slice(1)
          .get()
          .reverse()
     )
        .insertBefore("div[id|=block]:first");
    

    http://jsfiddle.net/8adwS/

    Also note that you can add the array reverse syntax to the jQuery function syntax, which would save you a selector.

提交回复
热议问题