How to change the number of rows in the textarea using jQuery

Josh R picture Josh R · Dec 11, 2010 · Viewed 31.5k times · Source

I have a textarea with 5 lines. I want to show only one line and on focus it should show remaining 4 lines.

Answer

Vincent Ramdhanie picture Vincent Ramdhanie · Dec 11, 2010

You can try something like this:

     $(document).ready(function(){

    $('#moo').focus(function(){
        $(this).attr('rows', '4');
    });
});

where moo is your textarea.