I ran into an issue where I couldn't get my test of a checkbox wouldn't work. Using JQuery inside of an "if" statement seemed to not work but when I took it out of the if statement and put the result into a variable it worked fine.
For example, if I do it the following ways:
OR
They don't seem to work. It will always treat it as "true" regardless of whether the checkbox is checked.
But if I do this:
It works fine.
Why can't you put the JQuery inside the "if" statement?
Thanks,
Tom
For example, if I do it the following ways:
Code:
if($("input:checkbox").is(":checked") == false)
{
// Do something if not checked
}
OR
Code:
if(!$("input:checkbox").is(":checked"))
{
// Do something if not checked
}
They don't seem to work. It will always treat it as "true" regardless of whether the checkbox is checked.
But if I do this:
Code:
allFilled = $("input:checkbox").is(":checked");
if(!allFilled)
{
// Do something if not checked
}
It works fine.
Why can't you put the JQuery inside the "if" statement?
Thanks,
Tom