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

  Work with me!


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 )

Thank you for reading! And see you soon on Strangebuzz! ๐Ÿ˜‰

COil