Im using this to check the maxlength of the textarea rather than using maxlength which is not supported in IE8-9.
In IE8 if I paste a 500 byte character focus is lost on the textarea element. The character can not be selected or deleted.
How do I maintain focus on the element?
$('textarea[maxlength]').bind('keypress keydown keyup paste change', function(){
var element = this;
setTimeout(function() { //Get the value
var text = $(element).val();
var limit = $(element).attr('maxlength'); //Get the maxlength
length = new Number(text.length); //counter increase
counter = limit-length;
$('#feedbackNum_counter').text(counter);
//Check if the length exceeds what is permitted
if (text.length > limit) {
$(element).prop('readOnly',true);
$(element).val(text.substr(0, limit)); //Truncate the text if necessary
$('#feedbackNum_counter').text(0)
}
},1)
});