Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract element value in react

Tags:

reactjs

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

like image 927
faisaljanjua Avatar asked Dec 17 '25 06:12

faisaljanjua


1 Answers

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>
like image 137
TimoStaudinger Avatar answered Dec 19 '25 22:12

TimoStaudinger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!