I’m new to Javascript. I set up a word counter on a form using Javascript. It works great in all browsers except, you guess it - IE. In both IE9 and IE11 the counter is unreliable, and the whole field can ‘freeze up’ and not allow you to click in it and edit anything.
Does anyone know why it’s breaking in IE? And if it can’t be fixed in a simple way, is there a way to conditionally use the script only if the browser is not IE?
Here’s a demo of the form: http://nzensandbox.wpmakeover.com/
And the code:
$("#field_advstatement").on('keydown', function(e) {
var words = $.trim(this.value).length ? this.value.match(/\S+/g).length : 0;
if (words <= 50) {
$('#display_count2').text(words);
$('#word_left2').text(50-words)
}else{
if (e.which !== 8) e.preventDefault();
}
});
Any help would be greatly appreciated.