How can I remove all the elements with a specific tag name using Javascript. For example, I did the following:
var els = document.getElementsByTagName("center");
and it returned an array of all the center
elements. How may I remove all these elements?
Coming from Remove all child elements of a DOM node in JavaScript and JavaScript DOM remove element I know that I can loop through els
, find the parent of each element and then remove that specific node. But is there anyother way provided by javascript. Like we can do $('center').remove()
in jquery and it removes all the elements with center
tag. Anything similar to that in Javascript?