Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Document Method-2 : createAttribute-2</title>
</head>
<body>
  <p id="sports" class="sportsClass swimClass">Dowon</p>
</body>
</html>
 
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;
};
///////////////////////////////////////////////////////
window.onload = function() {
  var el = document.getElementById('sports');
  js.log('NodeName: ', el.nodeName);
  js.log('NodeType: ', el.nodeType);
  js.log('NodeValue: ', el.nodeValue);
  js.log('tagName: ', el.tagName);
  js.log('textContent: ', el.textConent);
  
  js.log('----------------');
  var attrs = el.attributes;
  for ( var k = 0; k < attrs.length; k++) {
    js.log('atrributes: ', attrs[k].name);
  }
  
  js.log('----------------');
  attrs = el.classList;
  for ( k = 0; k < attrs.length; k++) {
    js.log('class list: ', attrs[k]);
  }
  
};
Output

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

Dismiss x