Hide scrollbar while still being able to scroll with mouse/keyboard [duplicate]

For future reference there is also a solution without jQuery – just have the wrapper div style contain overflow:hidden and use this JavaScript two-liner:

// get the width of the textarea minus scrollbar
var textareaWidth = document.getElementById("textarea").scrollWidth;

// width of our wrapper equals width of the inner part of the textarea
document.getElementById("wrapper").style.width = textareaWidth + "px";

See demo or complete HOWTO.

Update: you can use the same principle to create scrollable div without scrollbar: demo.

Leave a Comment