Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
Style.display = 'none' does not work on BBC.com Overlay Element

So this might be an odd question. But I tried to hide a certain HTML element on the bbc.com website with using element.style.display = 'none !important' in my Google Chrome Console. Strangely it does not hide the element as I would expect it. Maybe it is something minor and I am just overseeing something.

Here is the code I use:

var overlay = document.querySelector("div[class='fc-dialog-overlay']");
overlay.style.display = 'none !important';

I do not get an error and if I inspect the element it also contains the new property and looks like <div class="fc-dialog-overlay" style="display: none;"></div>, but it can still be seen. The same problem occurs with several other elements like the class='fc-consent-root'.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Note: Don't do the setAttribute thing below, use setProperty as shown in this answer to the earlier question. (I'll delete this answer when/if it's un-accepted by the OP.)


You're specifying an invalid property value; !important can be used in style rules but not in the specific values you assign via the style object. I'm surprised you're seeing the display: none in the style area. I don't with Chrome or Firefox when I do that (perhaps it was left over from having done .display = "none" and not seeing it work?):

const overlay = document.getElementById("example");
overlay.style.display = "none !important";
<div id="example">x</div>
<div>y</div>

If I right-click x and look at it, it doesn't have a style at all, even after the code runs.

You can still do it, you just have to assign to the entire style attribute so you get full rules parsing:

const overlay = document.getElementById("example");
overlay.setAttribute(
    "style",
    overlay.getAttribute("style") + "; display: none !important"
);
#example {
    display: block !important;
}
<div id="example">x</div>
<div>y</div>

Note that it works even though I have a conflicting !important rule applied via a stylesheet. That's because a stylesheet !important rule overrides an inline style unless the inline style also has !important.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!