4

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

2 Answers 2

10

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

document.getElementsByTagName("body")[0].style.overflowY = "auto";
Sign up to request clarification or add additional context in comments.

Comments

4

As an alternative to VisioN's answer you can use square brackets and a string to access it:

document.getElementByTagName("body")[0].style['overflow-y'] = "auto";

This is good if you don't know what the camelCase is.

1 Comment

Thank you too for mentioning that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.