By 09/02/2016 11 Comments

Styling and auto extend textarea in JQuery

  • Get JQuery from CDN in html head.

Example:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

  • Write the following CSS code in .css file.

Example:

textarea.txt-area-custom-style {
resize: none;
padding:12px 15px 12px 15px;
line-height: 22px;
overflow:hidden;
}

  • Write the following JQuery code in .js file.

Example:

$(document).ready(function() {
    $("#txt_post_contents").on("mousemove keyup keypress", function () { 
	var textField = document.getElementById("txt_post_contents");
	 if (textField.clientHeight < textField.scrollHeight) {
             textField.style.height = textField.scrollHeight + "px";
             if (textField.clientHeight < textField.scrollHeight) {
                textField.style.height = (textField.scrollHeight * 2 - textField.clientHeight) + "px";
             }
         }
    });
});

  • Write the following html code in .html file.

Example:

<textarea id="txt_post_contents" class="txt-area-custom-style" name="txt_post_contents" rows="3"></textarea>






Posted in: CSS, HTML, jQuery, Solutions

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .