0

I can't create a scroll from the "text / event-stream" data output to the div. Something that can do to correct this problem?

page.html

<!DOCTYPE html>
<html>
<head>
    <style>
    # out {
           display: table;
           width: 600px;
           height: 600px;
           text-align: center;
    </style>

    <script>
    var source = new EventSource("/stream");
    var mDiv = document.getElementByID('out');
    source.onmessage = function(event) {
        mDiv.scrollTop = 0
        mDiv.innerHTML += event.data + "<br/>"
    }
    </script>
</head>
<body>
    <div id="out"></div>
</body>
</html>
  • `mDiv` is `null`, as `#out` does not exist yet. You either need to wait `window.addEventListener('DOMContentLoaded', function() { /* your code goes here */ })`, or to put your ` – blex Sep 16 '20 at 19:05
  • Add `overflow: scroll;` into `#out` – Alberto Castillo Sep 16 '20 at 19:07
  • Does this answer your question? [How to compensate for Vertical Scrollbar when it is not yet present](https://stackoverflow.com/questions/9650762/how-to-compensate-for-vertical-scrollbar-when-it-is-not-yet-present) – Booboo Sep 16 '20 at 19:09

0 Answers0