I'm working with CKEditor for the past few months.But, now I'm facing issue
for deletion in CKEditor.
My Question is::
How do I get the lastly deleted element's HTML value in CKEditor.
When I click the Delete button, I want to get what is the element will
be Deleted and get Deleted elements HTML Value.
Anyone, please help me.
you can attach listener when editor content is ready, and check for delete or backspace press and get the last deleted content, an example could be like::
CKEDITOR.replace( 'your-editor', {
...,
on: {
contentDom: function () { //editor content ready
var myEditor = this;
//add listener
this.editable().attachListener( editor, 'key', function( evt ) {
//if delete or backspace pressed
if ( ( evt.data.keyCode in { 8: 1, 46: 1 } ) ) {
//get the last element
var lastElement = myEditor.elementPath().lastElement,
lastElementName = lastElement.getName(),
lastElementNode = lastElement.$; //native DOM object
//see what properties the node has
console.log(lastElementNode);
//you can use getAttribute to fetch specific attr
//for example, for img element's src attribute
console.log(lastElementNode.getAttribute("src"));
}
});
}
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.