I have successfully overridden the paste event on the document object, but now I want to trigger the onchange, oninput, and other input events in the event handler for the paste event.
document.addEventListener('paste', function (e) {
e.preventDefault();
var copiedText = e.clipboardData.getData("text/plain");
if (e.srcElement.type === 'text' || e.srcElement.type === 'textarea') {
var startPosition = e.srcElement.selectionStart;
var endPosition = e.srcElement.selectionEnd;
var len = e.srcElement.value.length;
var sel = e.srcElement.value.substring(startPosition, endPosition);
e.srcElement.value = e.srcElement.value.substring(0, startPosition) + copiedText +
e.srcElement.value.substring(endPosition, len);
}
$(e.srcElement).trigger("change");
$(e.srcElement).trigger("input");
$(e.srcElement).trigger("propertychange");
});
How can I trigger the change, input, or propertychange event for an input element?
This section of code is not functioning correctly.
$(e.srcElement).trigger("change");
$(e.srcElement).trigger("input");
$(e.srcElement).trigger("propertychange");