Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React - Get text of div on click without refs

Is there an example where we can retrieve the value of a React element without the usage of refs? Is that possible?

var Test = React.createClass({

  handleClick: function() {
    alert(this.text);
  },
  render: function() {
    <div className="div1" onClick={this.handleClick}> HEkudsbdsu </div>
  }
})
like image 573
chrisrhyno2003 Avatar asked Apr 04 '16 23:04

chrisrhyno2003


1 Answers

I found a working answer:

var Hello = React.createClass({
  handleClick: function(event) {
    alert(event.currentTarget.textContent);
  },
  render: function() {
    return <div className="div1" onClick={this.handleClick}> HEkudsbdsu </div>
  }
});
like image 123
chrisrhyno2003 Avatar answered Sep 19 '22 06:09

chrisrhyno2003