dojo/dom-geometry::getMarginSize()

Project owner:Eugene Lazutkin
since:V1.7

Returns an object that encodes the width and height of the node’s margin box

Usage

require(["dojo/dom-geometry", "dojo/dom", "dojo/dom-style"], function(domGeom, dom, style){
  var node = dom.byId("someNode");
  var computedStyle = style.getComputedStyle(node);
  var output = domGeom.getMarginSize(node, computedStyle);
});

Attributes

Arguments Type Description
node String|DOMNode The node to return the information for
computedStyle Object? This parameter accepts computed styles object. If this parameter is omitted, the function will call dojo/dom-style::getComputedStyle() to get one. It is a better calling dojo/dom-style::getComputedStyle() once, and then passing the reference as an argument, wherever possible.

Examples

require(["dojo/dom-geometry", "dojo/dom", "dojo/dom-style", "dojo/on", "dojo/json", "dojo/domReady!"],
function(domGeom, dom, style, on, JSON){
  on(dom.byId("command"), "click", function(){
    var node = dom.byId("example");
    var computedStyle = style.getComputedStyle(node);
    var output = domGeom.getMarginSize(node, computedStyle);
    dom.byId("output").innerHTML = JSON.stringify(output);
  });
});
<button id="command" type="button">getMarginSize()</button>
<div class="example" id="example">Some example node</div>
<p><strong>Output:</strong></p>
<pre id="output"></pre>
.example{
  margin: 1em;
  text-align: center;
  padding: 1em;
  border: 2px solid black;
  color: white;
  background-color: blue;
  width: 200px;
  height: 100px;
}
Error in the documentation? Can’t find what you are looking for? Let us know!