Adders Adders - 3 years ago 53
HTML Question

How to minimise textarea when clicking out of if

I have the following code to maximise a text area when you click into it. How can I return it to it's original size when I click out of the textarea?

$('textarea').focus(function () {
$(this).animate({ height: "300px" }, 500);
});

Answer Source

Here you go with the solution https://jsfiddle.net/k3aztqof/1/

$('textarea').focus(function () {
    $(this).animate({ height: "300px" }, 500);
}).focusout(function () {
    $(this).animate({ height: "100px" }, 500);
});
textarea{
  width: 500px;
  height: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea></textarea>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download