0

I have a textarea with a background, set by css. I want to remove this when the user has started the 4th line.

HTML

<textarea rows='7' cols='60' style='background(image.png)'></textarea>

Javascript:

 $(textarea).css("background","#fff");

I just need a trigger

Thanks

1 Answers1

2

give id for textarea and

   var text = $("#myTextArea").val();   
        var lines = text.split(/\r|\r\n|\n/);
        var count = lines.length;

        if(count>3){
        //your code to change background
        $(textarea).css("background","#fff");
        }

it may help you.

sasi
  • 4,192
  • 4
  • 28
  • 47
  • `\n` on its own is enough for the split, but this doesn't cover wrapped lines. For instance, if a user types 120 characters in the first line, the cursor will actually be on the third row of the textarea. – Andy E Feb 13 '13 at 10:54
  • 1
    @JackRenshaw wrap the above in a keyup event on your textarea – Nishant Jani Feb 13 '13 at 10:58