calling function onclick event
<th onClick={this.sort}>Grades</th>
and in Function, trying to get the value of text.
sort(e){
console.log(e.target);
}
e.target catch <th>Grades</th>
how can just get text ie Grades' without th
You can get the text inside the element via innerText:
sort (e) {
console.log(e.target.innerText);
}
However, in this case it may be better to pass the text in directly, depending on your use case:
<th onClick={() => this.sort('Grades')}>Grades</th>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With