add li to middle of the ul (jquery)

前端 未结 3 649
难免孤独
难免孤独 2021-01-02 17:00

How one can add li to middle of the ul.

For example if i have list like this:

  • 1
  • 2
  • 3<
3条回答
  •  醉话见心
    2021-01-02 17:39

    var middle = Math.ceil($("#myUL li").length / 2);
    $("#myUL li:nth-child(" + middle + ")").after('
  • Item New
  • ');

提交回复
热议问题