-2

I want to add these styles I present as CSS to HTML and Body tag using Javascript:

html, body {
  overflow-y:hidden;
  height:100%;
}

The question is HOW?

foxer
  • 811
  • 1
  • 6
  • 16

2 Answers2

1

That's rather easy:

var html = document.documentElement; // <html> tag
var body = document.body; // <body> tag

html.style.height = body.style.height = '100%';
html.style.overflowY = body.style.overflowY = 'hidden';
David
  • 3,552
  • 1
  • 13
  • 24
0

You can do this by using querySelector or, if there are multiple instances of the element, querySelectorAll. You do this like this:

document.querySelector("html").style.overflowY = "hidden";
document.querySelector("html").style.height = "100%";
document.querySelector("body").style.overflowY = "hidden";
document.querySelector("body").style.height = "100%";

If you don't like querySelector, you should know that there is a plethora of different ways to do this, like document.getElementByTagName("html")

Serket
  • 3,785
  • 3
  • 14
  • 45