Discussions » Development

Help me :( how to remove this div

§
Posted: 2025-04-08
Edited: 2025-04-08

Hey

how to remove this div. what will be the code?

§
Posted: 2025-04-08

Hi, it would be better to remove the whole IFrame, which is loaded from an external website.
The easiest option is to check to add the source of the iframe to your adblocker's block list, but if you want to use an userscript, you could use this code:


var elementToRemove = document.body.getElementsByTagName("IFRAME");
if(elementToRemove.length>0){
elementToRemove[0].remove(); //assuming it's always the first iframe in the page
}

§
Posted: 2025-04-08
Edited: 2025-04-08

But if for any reason you just want to delete the div, but not the whole iframe, you should make a script that runs on the domain of the iframe, and not on the domain of the main page (e.g. if the site you're browsing is example.com and the iframe comes from ads.net, the userscript should run on ads.net).
Once the script is running on the correct page, you can use this code to remove just the div (it's the same as above, assuming the div you want to remove is always the first in the page):
var elementToRemove = document.body.getElementsByTagName("DIV");
if(elementToRemove.length>0){
elementToRemove[0].remove();
}

Post reply

Sign in to post a reply.