Reputation:
I've got a site which has annoying features - f.e it detects adblock and puts on big rectangle on the video window saying that I should disable adblock. The code for this looks like this:
<div class="tvpoverlay_element" id="tvpoverlay_abdinfo" style="cursor: pointer;">
<div style="top: 20%; left: 0px; width: 100%; height: auto; position: absolute; display: block; pointer-events: auto;">
So if I insert display: none
in the second line, the rectangle would disappear, and I would be very happy. I wanted to make simple script to automate this process. I tried command:
document.getElementById('tvpoverlay_abdinfo').style.display = 'none'
but .getElementById()
returrns null. How can I get to this div and change the display, if the solution above doesn't work?
Upvotes: 0
Views: 99
Reputation: 408
First check that when you are triggering that code line, the element exists (e.g. if the app is using Angular or react or whatever JS Framework, those elements don't exist at the beginning)
Maybe is a good solution for you write a script to check if the element exist and then execute your code (How to wait until an element exists?)
The command is right, so just trigger it at the right moment.
If is inside an iframe, try this (Javascript - Get element from within an iFrame)
Upvotes: 2