In my website, I have created a div element using React Js and it's editable, here if the user edits the content it will trigger the onInput function.
r.createElement("div", {
dangerouslySetInnerHTML: {
__html: e
},
dir: "auto",
ref: "input",
spellCheck: this.props.spellCheck,
"data-tab": this.props.editable ? 1 : null ,
contentEditable: this.props.editable,
className: t,
onInput: this.onInput,
onPaste: this.onPaste,
onCut: this.onCut,
onKeyUp: this.onKeyUp,
onKeyPress: this.onKeyPress,
onMouseDown: this.onMouseDown,
onContextMenu: this.onContextMenu,
onFocus: this.props.onFocus,
onBlur: this.props.onBlur
}
I am trying to set the content to that element from the client chrome browser console and it's not triggering the onInput
event.
Is there a way to add input dynamically and call onInput
event which is attached for the element?
In my website, I have created a div element using React Js and it's editable, here if the user edits the content it will trigger the onInput function.
r.createElement("div", {
dangerouslySetInnerHTML: {
__html: e
},
dir: "auto",
ref: "input",
spellCheck: this.props.spellCheck,
"data-tab": this.props.editable ? 1 : null ,
contentEditable: this.props.editable,
className: t,
onInput: this.onInput,
onPaste: this.onPaste,
onCut: this.onCut,
onKeyUp: this.onKeyUp,
onKeyPress: this.onKeyPress,
onMouseDown: this.onMouseDown,
onContextMenu: this.onContextMenu,
onFocus: this.props.onFocus,
onBlur: this.props.onBlur
}
I am trying to set the content to that element from the client chrome browser console and it's not triggering the onInput
event.
Is there a way to add input dynamically and call onInput
event which is attached for the element?
1 Answer
Reset to default 11you can dispatch event from console
1.find dom node through querySelector.. , or select element in "Elements" tab and use $0;
const input = document.querySelector('[contentEditable]');
2.create event
const eventX = new Event('input', {bubbles: true});
3.change value
input.textContent = "TEST";
4.dispatch event
input.dispatchEvent(eventX)
jsfiddle DEMO test