I have a textarea with 5 lines. I want to show only one line and on focus it should show remaining 4 lines.
The variable lineHeight is set to the numeric value of the style property line-height of our TextArea . The variable tr represents the text in our TextArea and holds its dimensions as bounding properties. We divide the property boundingHeight by lineHeight to get the number of lines our text occupies.
I think you can do this with pure HTML. The wrap="hard" means that once the user has reached the end of the line - in this case, 20 characters - a newline will be inserted. Once the user has reached 100 characters - the same as filling in 5 lines with 20 characters - no more input will be allowed.
You can try something like this:
$(document).ready(function(){ $('#moo').focus(function(){ $(this).attr('rows', '4'); }); });
where moo is your textarea.
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 }); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With