Adam
Adam

Reputation: 9459

jQuery trigger when element is removed from ContentEditable

I'm attempting to trigger a function when an element is removed from a contenteditable div. eg. when the user backspaces and the element is removed.

I've tried the following which works, but not for the elements inside the contenteditable div:

$(document).bind("DOMNodeRemoved", function(e)
{
    alert("Removed: " + e.target.nodeName);
});

How else can this be done?

Upvotes: 2

Views: 198

Answers (1)

glortho
glortho

Reputation: 13198

There isn't a great way to do this AFAIK. Best I know is to cache the mark-up before editing begins and then compare current mark-up with cached mark-up on keydown (testing for backspace – keycode 8). Trigger custom event if you detect a full element deletion. Not great, requires a lot of micromanagement, but works.

Upvotes: 1

Related Questions