function count(){
var val = $.trim($('textarea').val()),
words = val.replace(/\s+/gi, ' ').split(' ').length,
chars = val.length;
if(!chars)words=0;
return words;
}
This function always return 0? Please help.
function count(){
var val = $.trim($('textarea').val()),
words = val.replace(/\s+/gi, ' ').split(' ').length,
chars = val.length;
if(!chars)words=0;
return words;
}
This function always return 0? Please help.
You can split the textarea value on spaces and then get the words length in it. Try this:
working Demo