简体   繁体   中英

How To Override CSS Styles in Shadow DOM?

This code is injecting div in my website, I want to turn the display:block; to display:none; . How do I override the styles?

  var template = document.getElementById("MDow-1");
  var div = document.createElement("div");
  div.setAttribute("style", "display: block !important; clear: both !important".replace(/\s/g, " ".repeat(parseInt(Math.random() * 29 + 1))));
  var shadow = div.attachShadow({mode: "closed"});
  shadow.innerHTML = template.innerHTML;
  document.body.appendChild(div);

This CSS style does not work.

.SelectorName { 
display: none; 
}

I'm not sure that I'm following your question, to change the display of the div you could use

div.style.display = "none"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM