This is probably not the best solution but i want t check if the text has been changed in the textarea element when clicking the button. Obviously using ".on("change keyup paste", function()" check anny changes to the textarea instantly. Because of this the textarea element will be checked two times:
First when editing the textarea Second when i hit the button
The idea is to only preform the check of the textarea once, when the button has been clicked. Is there a more suitable event handler function for this?
Script:
$('#btnClick').click(function () {
$("#textarea").on("change keyup paste", function() {
var PreviousVal = document.getElementById("textarea").innerHTML;
var currentVal = $(this).val();
if(currentVal == PreviousVal) {
alert("No changes where made");
}
else {
alert("textarea has been changed from " + '"' + PreviousVal + '"' + " to " + '"' + currentVal + '"');
}
})
});
HTML:
<textarea id="textarea">Hejsan</textarea><br/>
<input id="btnClick" type="button" value="Submit" />
data-*attribute and compare on click.