I thought I could do this:
$('body').on('focus', '[contenteditable]', e => {
var self = $(e)
self.data('before', self.html())
return self
})
but it's saying: "Cannot read property 'createDocumentFragment' of undefined"
$('body').on('focus', '[contenteditable]', myfocus)
function myfocus() {
var self = $(this)
self.data('before', self.html())
return self
}
p {
cursor:pointer
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p contenteditable>Click here to edit</p>
You have to use
$(e.target);In
myfocusfunction,thisis a reference that refers to the DOMelementthat triggered theevent.In the jquery function,
thisrefers to theeventcreated, so you can access theDOMelement usingevent.target.event.targetproperty returns the element that triggered theevent.