#6633 closed Bug (invalid)
No events after setData
| Reported by: | Matthias | Owned by: | |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | General | Version: | 3.4.1 |
| Keywords: | Cc: | karthick.ajk@… |
Description
After you set the editor data via editor.setData(html) no more (key) events are fired on the body.
Example Code:
editor.document.getBody().on("keyup", function() {
alert("keyup event");
}); editor.setData("...");
After that, the keyup event will never be fired again. Maybe the editor creates a complete new body when calling setData (which implicitly removes the listeners)?
Change History (3)
comment:1 Changed 15 years ago by
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
comment:2 Changed 15 years ago by
| Cc: | karthick.ajk@… added |
|---|
But when do i re-attach the events? Is there an event fired after the setData is complete?
comment:3 Changed 12 years ago by
To help future searchers: I found the answer at http://stackoverflow.com/questions/16054070/ckeditor-setdata-prevents-attaching-of-events-with-on-function
In particular, you attach on listeners the contentDom event, but you must also detach the listeners on contentDomUnload so that the new listeners work each time.

Yes, a new document is created when setData is used and you must re-attach any listeners that you applied to the document or its contents.