Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Dom CSS compoutedStyle">
  <meta charset="utf-8">
  <title>DOM CSS compoutedStyle</title>
</head>
<body>
  
  <div id="sports" style="font-size: 20px;">
    Sports
  </div>
  
</body>
</html>
 
#sports {
  position: absolute;
  left: 200px;
  top: 50px;
  font-size: 14px;
}
 
window.onload = function () {
  
  var el = document.getElementById('sports');
  if(el.currentStyle) {
    view = el.currentStyle;
  } else {
    view = el.ownerDocument.defaultView.getComputedStyle(el, '');
  }
  js.log('top: ', view.top);
  
  js.log('font-size: ', view['font-size']);
    
};
  
  
//////////////////////////////
//// utils
function idDisplay(nodes, desc) {
  var k, result = '', count = 0;
  if(nodes) {
    for(k = 0; k < nodes.length; k++) {
      result += nodes[k].id + ', ';
      ++count;
    }
    js.log(desc, ' --> ', count, ': ', result);
  } else {
    js.log(desc, ' There is nothing');
  }
}
var js = {
  lineNumber: 1
};
js.log = function(text) {
  var node, child, lineText;
  node = document.getElementById('result');
  if (!node) {
    node = document.createElement('div');
    node.id = 'result';
    document.body.appendChild(node);
  }
  child = document.createElement('div');
  lineText = js.lineNumber + '.';
  lineText = Array.isArray(text) ? lineText + '[' + text + ']' : lineText + text;
  if (arguments.length > 1) {
    for (var k = 1; k < arguments.length; k++) {
      lineText += arguments[k];
    }
  }
  child.innerText === undefined ? child.textContent = lineText : child.innerText = lineText;
  node.appendChild(child);
  js.lineNumber += 1;
  return this;
};
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x