Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6754345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:16:07+00:00 2026-05-26T13:16:07+00:00

I have created a jQuery elastic plugin. I have the problem that if I

  • 0

I have created a jQuery elastic plugin. I have the problem that if I write a word, such as “jQuery”, on the first line, and I press enter, the “jQuery” word will be hidden for a few milliseconds and then a new line will be inserted into the textarea.

My plugin page- http://jsfiddle.net/yash_wow/7F8aK/3/

Please help me solve this.

P.S. – I don’t want to use any other plugin and I don’t want code which inserts an extra line at the bottom of the textarea as all other elastic plugins do!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:16:08+00:00Added an answer on May 26, 2026 at 1:16 pm

    I did manage to tweak your plugin to work in Chrome here (untested on other browsers). Essentially I had to handle Enter in a special way to avoid it adding the new line to the bottom of the textbox and scrolling down to view it automatically before you get a chance to grow the textbox.

    I also had to add the .keyup() so that backspace worked as well.

    Here is the full javascript:

    /*
    Author - Yash Mathur
    */
    jQuery.fn.autoGrow = function() {
        return this.each(function() {
            var colsDefault = this.cols;
            var rowsDefault = this.rows;
    
            var grow = function() {
                growByRef(this);
            }
    
            var growByRef = function(obj, enterPressed) {
                var linesCount = 0;
                var lines = obj.value.split('\n');
    
                for (var i = lines.length - 1; i >= 0; --i) {
                    linesCount += Math.floor((lines[i].length / colsDefault) + 1);
                }
    
                if (enterPressed) linesCount++;
    
                if (linesCount > rowsDefault) obj.rows = linesCount;
                else obj.rows = rowsDefault;
            }
    
            var characterWidth = function(obj) {
                var characterWidth = 0;
                var temp1 = 0;
                var temp2 = 0;
                var tempCols = obj.cols;
    
                obj.cols = 1;
                temp1 = obj.offsetWidth;
                obj.cols = 2;
                temp2 = obj.offsetWidth;
                characterWidth = temp2 - temp1;
                obj.cols = tempCols;
    
                return characterWidth;
            }
    
            $(this).keypress(function(evt) {
                if (evt.which == 13) {
                    growByRef(this, true);
                    this.value += '\n';
                    return false;
                } else {
                    growByRef(this, false);
                }
            });
            $(this).keyup(function(evt) {
               if (evt.which == 13)
                  return false;
               growByRef(this, false); 
            });
            this.style.overflow = "hidden";
            //this.onkeyup = grow;
            this.onfocus = grow;
            this.onblur = grow;
            growByRef(this);
        });
    };
    $("textarea").autoGrow();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a jQuery plugin that works great with the exception of being
I have created one jQuery plugin to use in my own system. The problem:
I have created a tool using jQuery that will show certain table rows depending
I have created a jQuery plugin that grabs a JSON feed (in this case
I have created a jQuery animation that can be seen by clicking the Preview
I have created a dynamic list picker script using Jquery 1.3 and PHP that
I have created a drop down with jQuery that can be seen here by
I have created a dialog with the JQuery dialog plugin. My dialog is defined
I have created some JQuery that on click of specified HTML it then becomes
Here is my problem: The Problem I have created Tabs using jQuery which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.