[jQuery] Why does this If/Else statement fail?

[jQuery] Why does this If/Else statement fail?


Hello,
I have a pretty straightforward question. This is simple code; but
still I can't figure out why its not working.
This block of code works fine; its toggles a button graphic on mouse
hover:
var subscribeState = "off";
$('#subscribe').hover(function() {
$(this).attr("src", "images/btn_Subscribe_over.gif");
}, function() {
$(this).attr("src", "images/videos_subscribe_btn.jpg");
});
I want to add an if statement to it, so that it only swaps the graphic
if the "subscribeState" var is set to "off"
var subscribeState = "off";
$('#subscribe').hover(function() {
if(subscribeState == "off") {
$(this).attr("src", "images/btn_Subscribe_over.gif");
alert(subscribeState);}, function() {
$(this).attr("src", "images/videos_subscribe_btn.jpg");
alert(subscribeState);
}
});
But when I added the if statement I get a syntax error. Can anyone see
a problem in my code?
By the way, here is the code that sets the "subscribeStatus" to on/
active:
$('#subscribe').click(function() {
subscribeState = "clicked";
$(this).attr("src", "images/
thinking.gif").val("Subscribing...").css("enabled", "false").disabled
= true;
$.post("data/subscribe.aspx",
{ name: "John", time: "2pm" },
function(data) {
$(this).attr("src", "images/success.gif");
}); return false;
});
I also have a similar problem; this function always returns "Closed".
I expect that "cmtStatus" should toggle between "Open" and "Closed",
but alas - Open is never found (the alert always shows me "Closed"):
var cmtStatus = "Closed";
$("#postCmtBot").click(function() {
alert(cmtStatus);
if (cmtStatus = "Open") { $("#postCmtBot").html("Hide Post
Comment"); cmtStatus = "Closed"; }
else { $("#postCmtBot").html("Post Your Comment"); cmtStatus =
"Open"; }
alert(cmtStatus); return false;
});
Thank you for taking a look.
-- shawn