Get width and height of element

  • Thread starter Alejandro Penate-Diaz
  • Start date
A

Alejandro Penate-Diaz

Hi. Is there any way of getting an element real size from javascript, when
this element was previously assigned a width and height of 100%?
Thanks,
Alex.
 
J

Johan Nordberg

In IE you can use the getBoundingRect() method. Look ut up on MSDN for
documentation and examples. In most cases, you can use offsetHeight and
offsetWidth of the element, like

var e = document.getElementById("myDiv");
alert(e.offsetHeight);
alert(e.offsetWidth);
 
Joined
Jan 5, 2013
Messages
1
Reaction score
0
Hi. Is there any way of getting an element real size from javascript, when
this element was previously assigned a width and height of 100%?
Thanks,
Alex.

yes you can do this with the help of jQuery.


$(document).ready(function(){
$("div.width").append($("div.width").width()+" px");
$("div.innerWidth").append($("div.innerWidth").innerWidth()+" px");
$("div.outerWidth").append($("div.outerWidth").outerWidth()+" px");
});
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top