21

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

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Josh R
  • 1,309
  • 6
  • 19
  • 31

3 Answers3

33

You can try something like this:

     $(document).ready(function(){

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

where moo is your textarea.

Vincent Ramdhanie
  • 102,349
  • 23
  • 137
  • 192
6
jQuery(function($){
  $('#foo').focus(function(){
    $(this).attr('rows',5);
  }).blur(function(){
    $(this).attr('rows',1);
  });
});

Or, using less jQuery, less typing, and getting a hair more performance:

jQuery(function($){
  $('#foo')
    .focus(function(){ this.rows=5 })
    .blur( function(){ this.rows=1 });
});
Phrogz
  • 296,393
  • 112
  • 651
  • 745
0

Try this

$('#textboxid').focus(function()
    {
       $(this).animate({'height': '185px'}, 'slow' );//Expand the textarea on clicking on it
       return false;
     });
  • :Please be more descriptive about your solution. Refer:[How to Answer](http://stackoverflow.com/questions/how-to-answer) – askmish Oct 20 '12 at 01:27