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 7854847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:12:25+00:00 2026-06-02T20:12:25+00:00

What I’m trying to do is this: You click in a textarea, and it’ll

  • 0

What I’m trying to do is this:

You click in a textarea, and it’ll expand to 100px. Normally it’s at 50px. If you click outside (or trigger the blur event after clicking in the textarea…) it should go back to it’s normal 50px height.

If you trigger the change event by entering something into the textarea, I want to be able to click on the submit button without it triggering the blur (to move it back to 50px).

Am I on the right track?

var expandTextarea = function() {
$('.js-textarea-slide').on('click', function(e) {
    var typed = false;
    $(this).change(function() {
        typed = true;
    });
    $(this).animate({
        height: '100'
    }, 0);
});

$('.js-textarea-slide').blur(function(typed, e) {
    if (!typed) {
        alert('yo');
        return false;
    } else {
        
        $(this).animate({
            height: '50'
        }, 0);
    }
});
};

http://jsfiddle.net/khE4A/

  • 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-06-02T20:12:27+00:00Added an answer on June 2, 2026 at 8:12 pm

    http://jsfiddle.net/khE4A/4/

    var expandTextarea = function() {
    
        //Note that this is in a scope such that the click, blur and change handlers can all see it
        var typed = false;
    
        $('.js-textarea-slide').on('click', function(e) {
            //If you bind the change handler in here, it will be bound every time the click event
            //is fired, not just once like you want it to be
            $(this).animate({
                height: '100'
            }, 0);
        }).change(function() {
            typed = true;
        });
    
        //Note that I got rid of typed and e.
        //If typed were included here, it would not have the value of the typed on line 4.
        //Rather, it would have the value of whatever jQuery's event processing passes as the first
        //parameter.  In addition, it would hide the typed on line 4 from being accessible since
        //they have the same name.
        //Also, I got rid of the e parameter because it's not used, and in JavaScript, it's perfectly
        //acceptable to have a paramter calling/definition count mismatch.
        $('.js-textarea-slide').blur(function() {
            if (!typed) {
                $(this).animate({
                    height: '50'
                }, 0);
            }
        });
    
    };
    
    //Since expandTextarea doesn't depend on the context it's called from, there's no need to wrap it
    //in an extra function.
    $(expandTextarea);​
    

    Note that this follows the logic you described in your question, not what your code was trying to do. Anyway, a few important changes:

    Your change event would be bound every time the textarea was clicked instead of once. For example, if you clicked on the textarea 3 times, you would bind the event 3 times instead of just the 1 time required.

    Also, the part that actually made the code broken was that typed was out of scope of the blur handler. Giving a callback a parameter with a certain name does not pull that variable into scope. In fact, it would mask it if the variable had been in a previously accessible scope.

    Another [pedantic] thing:

    $(function() {
        expandTextarea();
    });​
    

    The function wrapping is unnecessary. As expandTextarea does not use this, you can use the function directly:

    $(expandTextarea);
    

    Anyway, given the description of the problem in your question, I believe what you’re looking for is: http://jsfiddle.net/khE4A/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.