question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make onChange work for contenteditable

See original GitHub issue

Apparently 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:closed
  • Created 10 years ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

17reactions
gaearoncommented, Dec 23, 2014

Just checking in here to say a combination of onInput and a mutation observer covers modern browsers and IE11.

13reactions
willwhitneycommented, Feb 28, 2014

@edwardmsmith It may not work on older browsers, but for modern browsers you can use the onInput callback like so:

<div
  contentEditable="true"
  onInput={function(e) {
    console.log("woohoo!");
  }}
>initial content</div>

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found