How to remove an element using pure JavaScript?


Write a custom script and trying to remove an html element.

Wrote a script:

document.getElementsByTagName( "html" ).remove();

But it in any does not want to work. Tell me, why?
July 2nd 19 at 14:04
2 answers
July 2nd 19 at 14:06
getElementsByTagName returns an array.

so going to work.

document.getElementsByTagName( "html" )[0].remove();
only instead of an array collection - Kelsie.Purdy commented on July 2nd 19 at 14:09
in the General case, an array is a special case of a collection, in the context of a JS equivalent as there are no restrictions on the types of the array elements. - evan.Hess commented on July 2nd 19 at 14:12
in the context of a javascript array is an object whose prototype chain is Array.prototype. Have returned by this method object is no
document.getElementsByTagName( "html" ) instanceof Array //false

Accordingly, there are no methods on the object. - Kelsie.Purdy commented on July 2nd 19 at 14:15
July 2nd 19 at 14:08
var element = document.getElementsByTagName( "p" )[0];

Find more questions by tags JavaScript