Make onChange work for contenteditable
See original GitHub issueApparently it doesn’t, but it would be pretty awesome if it did. We already listen for DOMCharacterDataModified
so I don’t think it should be too terrible. Tangentially it would be great to stop using mutation events and switch over to observers (let’s not do that here though unless it dovetails really nicely).
Interested @spicyj?
Issue Analytics
- State:
- Created 10 years ago
- Comments:19 (9 by maintainers)
Top Results From Across the Web
onChange event with contenteditable - javascript
1. onInput event is very poor solution. first reason - it happens every time when user change even a single letter. · 4....
Read more >Listen to changes on a contenteditable element - Coderwall
Let's make an contenteditable element: ... Since contenteditable elements doesn't have change event my first idea was to use key events.
Read more >Make any HTML element editable with contenteditable attribute
Any element's content can be made editable same way form fields are, even divs, by using the contenteditable attribute. You can just edit…...
Read more >ContentEditable Events - CodePen
Just a quick little pen to test what events are best to listen for in a simple contenteditable tag...
Read more >JavaScript : React.js: onChange event for contentEditable
JavaScript : React.js: onChange event for contentEditable [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] JavaScript ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just checking in here to say a combination of
onInput
and a mutation observer covers modern browsers and IE11.@edwardmsmith It may not work on older browsers, but for modern browsers you can use the onInput callback like so:
Edit: if you do that, be very sure not to use the app state for that ‘initial content’. That will make it a controlled component that gets rerendered every time, and the user’s cursor will jump to the beginning of the text with every keypress.