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.
What version of jQuery are you using? In versions >1.6 they want people to use
.prop()
instead of.attr()
for properties likedisabled
,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 statementvariable_a === variable_b ? true : false
. The result ofvariable_a === variable_b
will always betrue
orfalse
, so you don't need the? true : false
part.Hope this helps.