How to find out if the img tag from the carriage node remains in the html editor?

I am using the html editor to edit the content. Now I need to make sure that a very special element is not deleted (images with a special class).

For cases of using an uncomplicated selection / range with BACKSPACE, DELETE, CTRL + X / CMD + X, I have found a solution, but I'm still looking for a solution for the case where the choice / range is not and the following Backspace will delete one of my special images.

How can I tell if the next Backspace / Delete will remove one of these img tags?

Example: CARET marks the position of the cursor / cursor. If Backspace is clicked, the image will be deleted. How can I detect this case?

<p>Some Text <b>here <img class="my class" src="..."/></b>CARET some text</p>
+3
source share
2

onkeyup ( onselectionchange), IE. , "" jQuery.

function detectClass(){
    var range, parentR, parentL;
    range = document.selection.createRange();
    range.moveStart('character',1);
    range.moveEnd('character',1);
    parentR = range.parentElement();
    range.moveStart('character',-2);
    range.moveEnd('character',-2);
    parentL = range.parentElement();
    if (parentR.className == 'special'){/* special on right */}
    if (parentL.className == 'special'){/* special on left */}
    return;
}
+1

, , . Rangy IE < 9, , .

, Delete.

fooobar.com/questions/773128/...

+1

All Articles