jQuery focusin and append problem when textarea focus

Posted by Frozzare on Stack Overflow See other posts from Stack Overflow or by Frozzare
Published on 2010-05-13T22:36:44Z Indexed on 2010/05/13 22:44 UTC
Read the original article Hit count: 298

Filed under:
|
|
|

Hello guys.

I having problem with append() when the textbox is focus the second time.

var i = 1;    
$('textarea').live('focusin', function(){               
        $(this).keydown(function(e){
               var code = e.which;
            if(code === 13) { 
                i++;
                $('#linenumbers').append('<li>' + i + '</li>');}
    });

This code will append on

  • tag for each number, 2,3,4,5 (the first li is allread added, that why i=1) But when the user focus out and then focus in again it add two li foreache keydown,
    6 and 7 = first keydown 8 and 9 = second keydown

    third focus it add 3 numbers, and so on..

    How can i check that i just add one li each time you hit enter.

    Hope you get the problem!

  • © Stack Overflow or respective owner

    Related posts about jQuery

    Related posts about focus