Is there a cross browser method to get the size of an HTML element inside borders and padding?
-
Is there a cross browser javascript method to get the height and width of an HTML element without including the size of the margins, border or padding (e.g. just the padding)? I need to do this for both div elements and img elements. offsetWidth and offsetHeight include padding and border. clientWidth and clientHeight don't appear to be cross browser enough, may not work on inline elements (like img) and I've seen warnings about how IE returns bad values when there is browser zoom active.
-
Answer:
jQuery also has innerWidth() and innerHeight() function, which doesn't include margin and border (but still includes padding). http://api.jquery.com/innerWidth/
Ryan Ye at Quora Visit the source
Other answers
jQuery does this with width() and height(). I'd say don't reinvent the wheel on this one. You can see their solution beginning with line 5389. https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js
Todd Iceton
Related Q & A:
- What Is A Good Browser For N70?Best solution by Yahoo! Answers
- How to access a non static method in an abstract class's static method?Best solution by Stack Overflow
- How to get actual return type of a generic static method in Java?Best solution by stackoverflow.com
- how to get the size of an image without downloading it?Best solution by Stack Overflow
- How can I get a text alert when I get an email?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.