I am using jQuery Autosize to enable automatic height for textarea elements.
When I focus the textarea it works great.
If I blur the texture I would like to remove the height to the texture to resize the height to the default value.
I would like to know what should I do on blur action in order to keep the textarea to the default value.
Here is what I am trying to do on javascript console to test my script.
When I load the page the textarea is on blur state:
$('#announcement').css('height'); // "36px"
If I focus the textarea:
$('#announcement').css('height'); // "90px"
$('#announcement').removeAttr('height');
$('#announcement').css('height'); // "90px"
// why do I continue to get this value even if I removed the Attribute height?
I know I can simply fix my problem simply making on blur action
$('#announcement').css('height', '36px');
but I would like o avoid to set css properties in javascript code.
Any ideas?
You can clear the
style.heightset directly on the element with this:See working example here: http://jsfiddle.net/jfriend00/LXspR/
In your example,
removeAttr()works on attributes, not style properties likestyle.height..css("height")works onstyle.height.