Reputation: 431
I am trying to remove ads on a website in userscript, but .remove()
and style.display="none"
doesn't seem to work.
My code so far:
var adTop = document.getElementsByName('abp leaderboard-abp')[0];
adTop.style.display="none";
var adBt = document.querySelectorAll('.profile-ads-container')[0];
adBt.style.display="none";
var adLeft = document.querySelectorAll('.abp abp-container left-abp')[0];
adLeft.style.display="none";
var adRight = document.querySelectorAll('.abp abp-container right-abp')[0];
adRight.style.display="none";
If anything else is wrong with my code, please let me know.
Upvotes: 0
Views: 479
Reputation: 1190
You are trying to select ads elements but you apply changes only to the first ad element using the [0]
you can instead select and loop over all of them to assign the required behavior or style.
for example :
document.querySelectorAll('.abp leaderboard-abp').forEach((elem) => {
elem.style.display = 'none';
});
** If this didn't work for you please provide a sample of the HTML you are working on.
Upvotes: 1