Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to get an HTML element actual width and height in JavaScript

1 Answer

0 votes
<!DOCTYPE html>
<html>
  <head>
    <style>
      #divid {
        height: 200px;
        width: 250px;
        padding: 10px;
        margin: 15px;
        border: 3px solid blue;
      }
    </style>
  </head>
  <body>
    <div id="divid">
      <p>javascript programming</p>
    </div>
    <button onclick="GetWidthHeight()">Click To get width and height</button>
    <script>
      function GetWidthHeight() {
        let element = document.getElementById("divid");
        let width = "Width: " + element.offsetHeight + "px";
        let height = "Height: " + element.offsetWidth + "px";
        console.log(width);
        console.log(height);
      }
    </script>
  </body>
</html>



<!--
run:

"Width: 226px"
"Height: 276px"

-->

 



answered Feb 3, 2021 by avibootz

Related questions

1 answer 207 views
1 answer 203 views
203 views asked Nov 16, 2020 by avibootz
2 answers 332 views
1 answer 190 views
190 views asked May 25, 2016 by avibootz
2 answers 263 views
1 answer 172 views
...