Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
  <style>
    #inner2 {
      color: blue;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <div id="outermost">Outermost
    <div id="inner1">Inner 1
      <div id="inner2">Inner 2</div>
    </div>
  </div>
</body>
</html>
  
 
(function() {
  
  var inner2 = document.getElementById("inner2");
  
  display("inner2.id = " + inner2.id);
  display("inner2.parentNode.id = " + inner2.parentNode.id);
  display("inner2.parentNode.parentNode.id = " + inner2.parentNode.parentNode.id);
  
  display("Try clicking the blue 'inner2' above");
  
  inner2.onclick = function(e) {
    display("Click: this.id = " + e.target.id);
    if (this.parentNode) {
      display("Click: this.parentNode.id = " + this.parentNode.id);
      if (this.parentNode.parentNode) {
        display("Click: this.parentNode.parentNode.id = " + this.parentNode.parentNode.id);
      }
    }
  };
  
  function display(msg) {
    var p = document.createElement('p');
    p.innerHTML = String(msg);
    document.body.appendChild(p);
  }
  
})();
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers