jQuery: How to check if button is disabled

You can use jQuery to trigger a button click from the client.  In this certain situation, I needed to make sure the button was not disabled prior to clicking.  In jQuery you can use the “is” function to check if the button is disabled like this:

<script type="text/javascript">
    $(document).ready(function() {
    if ($('#StartButton').is(':disabled') == false) {
            $('#StartButton').click();
        }
    });
</script>

 

Technorati Tags:


Published 16 December 2009 03:25 PM by Jeff Widmer
Filed under:

Comments

# tony said on 22 April, 2010 08:00 PM

$('#StartButton').is(':disabled') == false ???? take out the == false and negate the statement

# Phil said on 14 December, 2010 05:35 AM

Totally agree with Tony.  That is bad practice in English, let alone Javascript.  The equivalent to this in the English language is like saying: "If the button is NOT NOT disabled then don't do something"

# Michel said on 12 January, 2012 10:10 AM

Phil - In Javascript, =, ==, === have different functionality.

Check the following reference link for info on those and others: developer.mozilla.org/.../Comparison_Operators

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Search

Go

This Blog

News

Syndication