Sameer Sheikh Sameer Sheikh - 7 months ago 20
Javascript Question

How can I use jQuery $(this) in react js function

I am working on reactjs and on click I am calling a function.

In that function I want to use jQuery

$this
to change the text of that element.
Is it possible to do so?

Or is there any way with reactjs to change the current elements text?

Answer

If you need just change text for element that was clicked you can do it like this

var Component = React.createClass({
    handleClick(e) {
        e.currentTarget.innerHTML = 'New Text';
    },

    render() {
        return <div onClick={this.handleClick}>Change Text</div>;
    }
});

Example

and using jQuery in our case is not necessary

Comments