Objective

Create a polyfill for the append() method of the Element interface.

Difficulty

Easy

Description

In the chapter HTML DOM — Elements, we got to know about the append() method of the Element interface that allows us to bulk-insert nodes into the DOM.

It can accept a variable number of arguments and then insert them all at once into the DOM.

If you're unaware of the append() method, then please consider understanding how it works, in HTML DOM — Elements — Bulk-inserting Nodes, before proceeding with this exercise.

Now the thing is that some browsers don't support the append() method. That is, we just can't invoke append() on these browsers as it's just not there!

In this exercise, you have to create a polyfill of append(), i.e. define it manually in JavaScript.

Your implementation must behave exactly like the native implementation of append(). That is,

  • The method MUST accept a variable number of arguments.
  • If an argument is not a Node instance, it MUST be coerced into a string.
  • The given nodes MUST be inserted into the DOM, all at once.