How can I split an HTML element?

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

Was this solution helpful to you?

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:

Just Added Q & A:

Find solution

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.