HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> #outerDiv{ height:150px; width:200px; border:1px solid black; overflow: auto; } #innerDiv{ height:1500px; width:2000px; } </style> </head> <body> <p>Click on the button to get the total width of the scrolling element.</p> <button onclick="myFunction()">Click Me</button> <p id="point"></p> <div id="outerDiv"> <div id="innerDiv">Some content</div> </div> <p><strong>Note</strong>: scrollWidth = padding-left + padding-right + width = 0 + 0 + 2000 = 2000.</p> <script> var x = document.getElementById("point"); var elem = document.getElementById("innerDiv"); function myFunction(){ x.innerHTML = elem.scrollWidth; } </script> </body> </html>
OUTPUT
×

Save as Private