jQuery Disabled no longer working on my Win8.1 machine

63 views Asked by At

I have (successfully) been using the following on my old Vista machine:

var isIE = isInternetExplorer();

$("#divTablesButton" + (isIE ? "" : " :input"))
    .attr( "disabled", this.m_Array1.length === this.m_Array2.length ? true : false );

where divTablesButton is a button and isInternetExplorer is the function (which still seems to be working fine):

function isInternetExplorer() {
    return ( getInternetExplorerVersion() < 0 ? false : true );
};

function getInternetExplorerVersion() {
    // Returns the version of Internet Explorer or a -1
    // (indicating the use of another browser).
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
};

But now I have noticed this does not work on my Win 8.1 machine with the newest versions of IE and Chrome.

Anyone know what is up? To clarify, it's the attr("disabled" bit that is wrong. The buttons do not disable.

1

There are 1 answers

6
grammar On BEST ANSWER

What version of jQuery are you using? In versions >1.6 they want people to use .prop() instead of .attr() for properties like disabled, required, checked etc. (things that are booleans). This older SO question will explain better than I can.

Try using prop() instead like below. Additionally, there's a piece of your code that you can remove. You've written a statement variable_a === variable_b ? true : false. The result of variable_a === variable_b will always be true or false, so you don't need the ? true : false part.

var isIE = isInternetExplorer();
$("#divTablesButton" + (isIE ? "" : " :input")).prop("disabled", this.m_Array1.length === this.m_Array2.length);

Hope this helps.