Open In App

HTML DOM document scrollingElement Property

The scrollingElement property of the document returns a reference to the element that scrolls the document.

In standards mode, this is the root element of the document. Whereas in quirks mode, It returns the HTML body element or NULL.



Syntax:

let elem = document.scrollingElement;

Return Value:



Example: In this example, we are getting the scrolling element using this property.




<!DOCTYPE html>
<html>
   
<body>
    <h1>GeeksforGeeks</h1>
    <button onclick="get()">
        Get ScrollingElement
    </button>
 
    <script type="text/javascript">
        function get() {
            let Elm = document.scrollingElement;
            Elm.scrollTop = 0;
            console.log(Elm)
        }
    </script>
</body>
   
</html>

Output:

 

Supported Browsers:

Article Tags :