2

I have a keyup function on text area. When user press enter, cursor is going to next line and calculating white space.How do I remove it ?

Here is my code.

data.keyup('#id',function(e)
                   {

                       code= (e.keyCode ? e.keyCode : e.which);
                         if (code == 13) { 
                                var xyz = $("#test").val();
                                xyz.length;
                             }
user2261231
  • 109
  • 2
  • 13

2 Answers2

1
jQuery.fn.cleanWhitespace = function() {
    textNodes = this.contents().filter(
        function() { return (this.nodeType == 3 && !/\S/.test(this.nodeValue)); })
        .remove();
    return this;
}


$('selector').cleanWhitespace();

see here

Community
  • 1
  • 1
PSR
  • 39,804
  • 41
  • 111
  • 151
1

I think you should try simple way like this

 if (code == 13) 
 {
                var xyz = $.trim($("#id").val()).length
                alert(xyz);
 }
Dhaval Marthak
  • 17,246
  • 6
  • 46
  • 68
  • :This is working but say when user presses back space continuously and hit enter, it is not working, it is calculating the space. – user2261231 Apr 15 '13 at 10:17