Swaraj ghosh Swaraj ghosh - 1 month ago 11
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;
return(
//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:
<ul>
<li> POC 1</li>
</ul>
</div>
</div>
)
};

Answer

Make a new function using bind.

onClick={this.viewMore.bind(this, attributeId)}
Comments