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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,181 questions

56,073 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 282 views
1 answer 274 views
274 views asked Nov 16, 2020 by avibootz
2 answers 410 views
1 answer 257 views
257 views asked May 25, 2016 by avibootz
2 answers 362 views
1 answer 248 views
...