Javascript Form How to - Get how much is textarea scrolled








Question

We would like to know how to get how much is textarea scrolled.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!--from  w ww . j a  v a2s  . c o m-->
    document.getElementById("b").onclick = function() {
        console.log(document.getElementById("t").scrollTop);
    };
}
</script>
</head>
<body>
  <textarea id="t" rows=10 cols=10> </textarea>
  <button id="b">scrollTop</button>
</body>
</html>

The code above is rendered as follows: