Deleting all elements of an HTML page having a given class with JavaScript
Published on 2024-10-10 • Modified on 2024-10-10
This snippet shows how to delete all elements of an HTML page having a given class with JavaScript. It is a valuable snippet when buying stuff on Amazon and wanting to hide unavailable products. For example, go to this webpage, select a produxt size, like ยซ XXS/XS ยป, then open your browser JavaScript console and run the snippet below. The unavailable products have been removed, making the page cleaner.
document.querySelectorAll('.a-button-unavailable').forEach(element => element.remove());
More on Stackoverflow Read the doc More on the web Random snippet
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky ๐ฆ
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges ๐ .
Thank you for reading! And see you soon on Strangebuzz! ๐
