Skip to content
Advertisement

How to remove all HTML elements after the using javascript? [closed]

I have a website where, under a certain condition, I want to remove every element after the <header> tag. How can I do this with javascript?

JavaScript

Advertisement

Answer

The handy-dandy chainable :not selector could be useful. It doesn’t remove elements by order, as you asked, but maybe it’s a solution here.

JavaScript
JavaScript

Otherwise you’ll have to work through the nodeList and check nodeType until you get to a script. This would be safer if you have other elements after the scripts.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement