0

Just wanted to know if anyone knew a way I can select and style the html tag directly after looking for :checked in css.

#btnControl:checked ??? html {
    overflow: hidden;
}

Any feedback will be greatly appreciated! : )

Best, Jonathan

Jonathan002
  • 7,041
  • 4
  • 23
  • 46

1 Answers1

0

You can't select parent using CSS. But you can use class to do this work. Use javascript to add/remove class to element. When checkbox checked, add class to html and when checkbox unchecked, remove class of html.

var checkbox = document.getElementById("checkbox");
var html = document.getElementsByTagName("html")[0];

checkbox.addEventListener("change", function(){ 
    if (checkbox.checked)
        html.classList.add("checked")
    else
        html.classList.remove("checked")
});
html.checked {
    background: orange;
}
<label for="checkbox">Click on checkbox</label>
<input id="checkbox" type="checkbox" />
Mohammad
  • 19,228
  • 14
  • 49
  • 73
  • Thanks for this answer. Pretty bummed that we can't do this yet in css as I'm trying to stay away from javascript as much as possible. – Jonathan002 May 18 '16 at 14:36