After I click on a li-element where the class-attribute contains “disabled selected”, disabled gets the value “true” but after stepping out the function the last if-statement is called.
var disabled = false;
$("li").click(function () {
if ($(this).attr("class") == "disabled selected") {
disabled = true;
}
});
if (disabled) {
alert("disabled is true");
}
if (!disabled) {
alert("disabled is false");
}
You should move both the
ifstatements inside the click handler.