I need to call React function (this.clearMath()) from JQ function
$('.input-content').focus(
function(){
this.clearMath()
})
I got Uncaught TypeError: this.clearMath is not a function. I think it´s caused by JQ that thinks this.
is reference to selected element $('.input-content')
.
Am I right? And how to distinguish between react this
an jquery this
to be able call my function? Thanks
You can solve this by doing this:
var _ = this;
$('.input-content').focus(
function(){
//this is still the input
_.clearMath()
})
So you save the this context before the selector so you can access the _ inside the function, its called a closure.
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