TutorialKart
index.html
►
Run
Reset
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <style> #myElement{ border:1px solid green; display: inline-block; } </style> </head> <body> <h2>Get Width of HTML Element using JavaScript</h2> <div id="myElement"> <p>Div Part 1.</p> <p>Div Part 2.</p> </div> <br><br> <button type="button" onclick="execute()">Click Me</button> <script> function execute(){ var element = document.getElementById('myElement'); var width = element.clientWidth; console.log("Width is " + width + "px"); } </script> </body> </html>