How to know which character(s) is(are) get deleted on backspace or delete button click when editing text in textarea.
I want to get character get deleted on backspace or delete button click to detect if deleted character is new line character.
Well you can do 2 things. You could either store the current value and compare it to the new value. Or you can try to catch the event before it really does what it has to do.
I found this prevent backspace function here check if its any use of you. You can use the SelectionStart function to find out what the position of your cursor is. By checking the keycode you can determine if the backspace or delete button was pressed. Delete will mean: position +1 is the character being deleted. Backspace will mean: position -1 is the character being deleted.
Because you are preventing backspace and/or delete to trigger their original event you have all the time to find those things out. Once you know all the information you needed to know you can manually remove the character from the string and update the text in the textarea.
Not sure if its the best way but it seems like something that could work like this.
Hope this helped you in any way.
©2020 All rights reserved.