remove all
  • from
      ?
  • 后端 未结 7 1140
    北荒
    北荒 2020-12-15 02:48

    I am appending li in a ul using the following code:

    for (var i = 1; i <= len; i++) {
        li = document.createElement(\'li\');
    
              
    
    
            
    7条回答
    •  不知归路
      2020-12-15 03:42

      If you are using jQuery, why don't you use it's benefits?

      adding

    • elements:

      $("
    • ").appendTo(root);

      removing all

    • elements:

      $(root).empty();
      

      deleting one

    • element:

      $("li:eq(3)",$(root)).remove();
      

      and if you are using raw js, you can use:

      document.getElementById("root").innerHTML = "";
      

    提交回复
    热议问题