Append multiple items in JavaScript

后端 未结 9 414
长情又很酷
长情又很酷 2020-12-07 20:58

I have the following function and I am trying to figure out a better way to append multiple items using appendChild().

When the user clicks on Add, each

9条回答
  •  无人及你
    2020-12-07 21:36

    It's possible to write your own function if you use the built in arguments object

    function appendMultipleNodes(){
      var args = [].slice.call(arguments);
      for (var x = 1; x < args.length; x++){
          args[0].appendChild(args[x])
      }
      return args[0]
    }
    

    Then you would call the function as such:

    appendMultipleNodes(parent, nodeOne, nodeTwo, nodeThree)
    

提交回复
热议问题