Change body.style.overflowY or X programmatically

I am trying to change the body of overflowY to "hidden" through a JavaScript function. I tried both of the following:

 document.body.style['overflow-y'] = 'hidden'; document.body.style.overflowY = "hidden"; 

In both cases, this did not work. However, in both cases, using only overflow without X or Y works fine!

Is there a way to change only overflowY or overflowX properties?

+4
source share
1 answer

Both cases should work in all browsers. I just tested Firefox 4, Chrome 11, and IE 9 and they all work fine. Either the browser with which you are testing has an error, or your problem lies elsewhere in your code; for example, a conflicting style declaration or an erroneous code in the same block.

Working example: http://jsfiddle.net/4dq64/

+10
source

All Articles