Swaraj ghosh Swaraj ghosh - 1 year ago 146
Javascript Question

OnClick Event binding in React.js

I would like to pass the parent div id on click of that div or any of child element of the same. But i am unable to achieve it. Please tell me where I am doing mistake. Code is Below.

viewMore: function(i,j){
console.log('You clicked: ', i );

render : function(){
var attributeId = "groups_";
attributeId+= index;
//parent div
<div className="groups" id={attributeId} onClick={this.viewMore}>
<div className="floatLeft"> Group Name: <h3>My Name</h3></div>
<span className="floatRight typeCd">POC</span>
<div className="clearfix"> Key Attributes:
<li> POC 1</li>

Answer Source

Make a new function using bind.

onClick={this.viewMore.bind(this, attributeId)}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download