Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the overflow property with Javascript

i need this function to enable vertical scrolling but not horizontal.

This doesn't works:

function scrollFunction() {
        // Scroll to top 
    document.getElementsByTagName('body')[0].style.overflow-y='auto';
}

While this does, but it enables both vertical and horizontal scrolling.

function scrollFunction() {
    // Scroll to top
    document.getElementsByTagName('body')[0].style.overflow='auto';
}

How can I specify just the overflow-y properly? Thanks

like image 675
Chain Avatar asked Sep 03 '25 06:09

Chain


1 Answers

Compound style properties are written in camelCase notation (the first letter is small):

document.getElementsByTagName("body")[0].style.overflowY = "auto";
like image 194
VisioN Avatar answered Sep 04 '25 19:09

VisioN