jQuery: deleting the last word from textarea’s cursor
Following with the completor suggestor I was playing, I had the need to delete the last word from cursor before the completor writes the suggestion selected.
Thanks to the previous function textarea.lastWord() it was very easy:
jQuery.fn.deleteLastWord = function() { this.each(function(){ if (this.selectionStart || this.selectionStart == '0') { var startPos = this.selectionStart; var endPos = this.selectionEnd; var scrollTop = this.scrollTop; var lastWord = $(this).lastWord(); startPos = startPos - lastWord.length; this.value = this.value.substring(0, startPos) + this.value.substring(endPos, this.value.length); this.focus(); this.selectionStart = startPos; this.selectionEnd = startPos; this.scrollTop = scrollTop; } else { alert("deleteLastWord not supported on this navigator"); } }); };
Example of use:
$('#my_textarea').deleteLastWord();
Don’t copy and paste from here, WP does weird stuff with code, download from here: http://gist.github.com/143822
This script is almost not tested, it works for me on FireFox 3.0.11 and Safari 4.0.1, so use it under your own responsability.
Abril 6th, 2011 at 11:49 am
I’ll try it now!!! Thanks…
Agosto 11th, 2015 at 1:30 am
Sistema de sonido inalambrico multiroom de alta definición por Wi-Fi.
Mayo 26th, 2016 at 7:17 am
Identifican las acciones de promoción desde la salud pública: La salud integral de los niños, pequeñas y adolescentes, de las personas de la tercera edad, de las personas con deficiencias, discapacidades, minusvalÃas y de la población del campo informal de la economÃa.
Julio 5th, 2016 at 7:01 pm
Real ones are quite rare, but you can buy kit car kits that are incredibly accurate for quite