Objective

Redefine the insertAdjacentElement() method of the Element interface, manually in JavaScript.

Difficulty

Average

Description

In the chapter HTML DOM — Elements, we learnt about the insertAdjacentElement() method of the Element interface.

It allows us to insert an element node inside another element node, either before the element, or after the element, or inside the element as its first child, or inside the element as its last child.

If your understanding of insertAdjacentElement() is a bit rusty, then you should consider learning about it first in the chapter HTML DOM — Elements.

So in this exercise, you have to redefine insertAdjacentElement() as a method of the Element interface, manually in JavaScript.

That is, it must behave exactly like the native insertAdjacentElement() method, as provided by the DOM API via its Element interface.

Although the browser support of insertAdjacentElement() is pretty amazing, we go on to redefine it only for the sake of better understanding the DOM API and JavaScript, in general. A lot of concepts will be put at test while redefining this method in JavaScript.