React

by boloneyshinobi

HTML

<div id="app"></div>

React

class GettingAttributes extends React.Component {
  constructor(props) {
    super(props)
    this.state = {value: 'Hello!'};
    
    this.bar = this.bar.bind(this);
  }
  
  bar(e){
  	this.setState({value: e.target.id})
  }
  
  render() {
    return (
      <div id="foo" onClick={this.bar}>
        <p>{this.state.value}</p>
      </div>
    );
  }
}

ReactDOM.render(<GettingAttributes />, document.querySelector("#app"))