Javascript detect scrollbar in textarea

Jamie picture Jamie · Jul 13, 2010 · Viewed 10k times · Source

I was wondering if anybody knows how I would go about detecting when the scrollbar appears inside a textarea.

I am currently using mootools for my JavaScript and I am having issues getting it to detect a scrollbar.

Answer

Tommaso Taruffi picture Tommaso Taruffi · Jul 13, 2010
function has_scrollbar(elem_id)
{
    const elem = document.getElementById(elem_id);
    if (elem.clientHeight < elem.scrollHeight)
        alert("The element has a vertical scrollbar!");
    else
        alert("The element doesn't have a vertical scrollbar.");
}

See this jsFiddle http://jsfiddle.net/qKNXH/