Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="//fb.me/react-0.13.1.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <div id="container" ></div>
  <div >Document clicked at: <span id="docClickTime">not clicked yet</span></div>
</body>
</html>
 
var Grandpa = React.createClass({
    
    getInitialState: function() {
        return {clickTime: '-'};
    },
    
    onClick: function(event) {
        this.setState({clickTime: (new Date().getTime())});
    },
    
    render: function() {
         return <div onClick={this.onClick}>
             <Dad  />
             <p>Grandpa Clicked At: {this.state.clickTime}</p>
         </div>;
    }
});
var Dad = React.createClass({
    getInitialState: function() {
        return {clickTime: '-'};
    },
    
    onClick: function(event) {
        event.stopPropagation();
        event.nativeEvent.stopPropagation();
        this.setState({clickTime: (new Date().getTime())});
    },
    
    render: function() {
        return  <div onClick={this.onClick}>
            <Son />
            <p>Dad Clicked At: {this.state.clickTime} AND STOP event propagation</p>
          </div>;
    }
});
var Son = React.createClass({
    getInitialState: function() {
        return {clickTime: '-'};
    },
    
    onClick: function(event) {
        this.setState({clickTime: (new Date().getTime())});
    },
    
    render: function() {
        return <div>
          <button onClick={this.onClick}>Click me</button>
          <p>Son Clicked At: {this.state.clickTime}</p>
        </div>;
    }
 
});
React.render(<Grandpa/>, document.getElementById('container'));
$(document).on('click', function(){
    $('#docClickTime').text(new Date().getTime());
});
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers