I am using this script to limit the characters on lines 1-3 on my textarea. It works in Firefox and Chrome. But in IE8, it shows an error: “Object doesn’t support this property or method” on the line that uses filter() method.
Here’s the code:
var result = jQuery('#result');
var my_textarea = jQuery('#mytext');
my_textarea.on('keyup', function(event){
var el = jQuery(this);
var lines = el.val().split('\n').length;
var chars = el.val().split('').filter(function(v){
return v != '\n';
}).length;
result.html('You have ' + lines + ' lines and ' + chars + ' chars');
if ((lines === 1 && chars > 20) || (lines === 2 && chars > 40) || (lines === 3 && chars > 60)) {
my_textarea.val( my_textarea.val() + "\n");
}
});
How do I resolve this?
filter(and several other methods onArray) are relatively new and aren’t implemented in older browsers – not just IE8, but older Firefox too.You may be interested in
array_filterfrom PHPJS, as this produces the same effect.Then again, looking at your code, wouldn’t this be simpler?