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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:17:04+00:00 2026-06-17T11:17:04+00:00

i just met a strange behavior jQuery and can’t figure out any more or

  • 0

i just met a strange behavior jQuery and can’t figure out any more or less slight solution.
Say, i have textarea and button. I want to disable button if textarea is empty.
For this i have a handler which does this job.

Here is the code:

// textarea control
var $textarea = $('#myTextarea');
var $button = $('#myButton');
$textarea.on('input propertychange', function() {
    if($textarea.val().length > 0) {
        $button.removeClass('disabled').removeAttr('disabled');
    } else {
        $button.addClass('disabled').attr('disabled', 'disabled');
    }
});
$button.on('click', function() {
    if ($button.attr("disabled") != null) {
        console.log('Disabled!');
        return false;
    } else {
        // do some stuff and eventually erase textarea 
        $textarea.val('');
    }
});

My trouble is when i erase textarea (the end of the code) it doesn’t disable the button. Any ideas would be appreciated (actually it’s slight adaptation of my code but the situation reflected pretty good, hope it would be clear for you, thanks!)

UPD
Nothing found on stackoverflow doesn’t help.

UPD2
As i said in the begin, i was looking not for workaround like force trigger event, i thought it’s possible to catch any event fired by $textarea.val(); Sure @Madbreaks and @epascarello ‘s solutions work pretty good, thanks guys.

  • 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-17T11:17:07+00:00Added an answer on June 17, 2026 at 11:17 am

    Maybe just add this:

    else {
        // do some stuff and eventually erase textarea 
        $textarea.val('');
        // notify
        $textarea.trigger('propertychange');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just met a strange behavior of facet_grid() in ggplot2 0.9, and I wonder
I am having a problem that I just can't seem to figure out. The
I just met something really strange of Python: >>> out=[[0]*3]*3 >>> out [[0, 0,
I'm applying UnitTest just for a while, and today I met something very strange.
I have just created a java tic-tac-toe game i would like to figure out
the title seems stupid. but i met the problem, now i can just type
Just learning the world of jquery, and all my googling gives examples like this:
We met a strange situation on SQL Server 2008 (SP1) - 10.0.2531.0 (X64) -
i've met a strange behaviour in Firefox with this simple script: <html> <head> <script
I just met the utilities ( com.sun.awt.AWTUtilities ) to make your JFrame really transparent.

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.