Search code examples
javascriptcssoverflow

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


Solution

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

    document.getElementsByTagName("body")[0].style.overflowY = "auto";