如何在列表项目中创建新的Div

我找到了相关的答案,但不像这个问题一样。
我的问题是如何在.widget-content创建新的Div内部列表项,如下所示?

主要HTML : 小提琴

 
  • Test Content
  • Test Content
  • Test Content
  • Test Content
  • Test Content
  • Test Content

我想要:

  
  • Test Content
  • Test Content
  • Test Content
    • Test Content
    • Test Content
    • Test Content

意味着添加2 Div,

拥有前3个子项,

拥有最后3个子项/列表项。 如何通过Jquery / JS简单地完成这项工作?
提前致谢。

你可以这样做

 var selectedIndex = 3; $(".widget-content li").each(function (index) { if (index == selectedIndex) { $(this).prevAll().wrapAll("
"); $(this).nextAll().andSelf().wrapAll("
"); } });
 

    js:我假设这里数是3

     window.onload = function () { for (var i = 0; i < 3; i++) { var div = document.createElement('div'); div.className = 'row' + i; div.innerHTML = '
  • Test Content
  • \
  • Test Content
  • \
  • Test Content
  • '; document.getElementById('ul1').appendChild(div); } };

    的jsfiddle