init.Monk
init.Monk

Reputation: 161

What is the Dojo equivalent of jQuery's innerHeight()?

In jQuery, we can use innerHeight to get the height of one element (including padding but not border.).

$("selector").innerHeight();

How can I get the same value by dojo?

What my solution is using

dojo.contentBox() //get the height of content box
dojo.style(node, "borderTopWidth") //get width of border-top
dojo.style(node, "borderBottomWidth"). //get width of border-left

Is there any easy way to do it?

Upvotes: 5

Views: 1854

Answers (1)

SimonMayer
SimonMayer

Reputation: 4926

Unfortunately, I don't think there is an easier way to do it.

You basically have three choices:

dojo.contentBox(node) // excludes border, padding and margin
dojo.position(node)   // includes border and padding; excludes margin
dojo.marginBox(node)  // includes border, padding and margin

So, you need to do what you suggested. Use dojo.contentBox(), then separately calculate the top and bottom border widths.

Alternatively you might want to place a <div> inside a <div>, so that you can set the border on the outer div and keep the padding on the inner div. You would then be able to get the required height from calling dojo.position() for the inner div.

<div id="outer" style="border: solid #000 1px;">
  <div id="inner" style="height: 20px; padding: 2px;">.</div>
</div>
<script>
  alert(dojo.position("inner").h) // 24
</script>

Upvotes: 1

Related Questions