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?
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?
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';
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")