"react": "^15.4.2"
I am having trouble triggering the change event from jquery for an input rendered with React. I need to do this for some end to end testing.
here's a sandbox as a full showcase: https://codesandbox.io/s/pp1k1kq3om with jquery already loaded.
If you run : $('#reactSlider').val(50).change() in the console, you'll notice that the change handler isn't called.
In the sandbox above there's also a pure html slider for comparison, that one works as expected (change function is called).
also tried to dispatch a new event like this:
var event = new Event('change') var target = $('#reactSlider')[0]; target.dispatchEvent(event); The above doesn't work either (and does work on the pure html slider).
import React from "react"; import { render } from "react-dom"; const changeHandler = event => { alert(`react slider changed:${event.target.value}`); }; const App = () => ( <div> <label htmlFor="reactSlider">react-slider</label> <input id="reactSlider" type="range" onChange={changeHandler} min={10} max={100} step={10} value={20} /> <p>run in the console: $('#reactSlider').val(50).change()</p> <br /> <br /> <p>Notice that for the React slider, the change event is not triggered.</p> </div> ); render(<App />, document.getElementById("root")); 
changeHandlerand also call it independently when you change the value programmatically. If you need to be able to handle change events from the console, set up a separate jQuery event handler that captures the change event and then call your function from within there