Using variables with if/else - syntax help
Hi,
I'm getting hung up on something that seems pretty simple, and I think I'm just making rookie syntax mistakes. I have a user dashboard that has a button on it to hide/show one of the panels, and this uses the cookie plugin to remember the user's preference. The cookie plugin provides a variable to use for controlling the display of the panel div, which then just toggles .show() and .hide(). (It returns either "block" or "none").
I want to add a little more to this so that it also changes the text on the toggle button based on whether the panel is hidden or shown.
Here's what I have - can anybody help me get the result of my if/else to populate the button value?
Thanks!
- $(document).ready(function() {
-
- // call the cookie class and set a cookie called viewState
- $.cookie("viewState");
-
- // create a variable and set it to the value of the cookie
- var theState = $.cookie("viewState");
- // these are the labels for the button
- var onState = "hide mentor steps";
- var offState = "show mentor steps";
- // put the right label on the button initially, based on the returned cookie variable
- var btnState =
- if (theState = "block") {
- return var onState;
- } else {
- return var offState;
- }
- $("#mentor-switch").val(btnState);
-
- // toggle the view state of the mentor steps
- $("#mentor-switch").toggle(
- function () {
- $("#dashboard-row-1").show("slow");
- // when clicked, set the cookie and variable to block, then change the button label
- $.cookie("viewState", "block");
- theState = "block";
- $("#mentor-switch").val(onState)
- },
- function () {
- $("#dashboard-row-1").hide("slow");
- // set the cookie and variable to none when clicked again, then change the button label
- $.cookie("viewState", "none");
- theState = "none";
- $("#mentor-switch").val(offState)
- });
-
- // update the hidden panels css to none, or block depending on the toggle event
- $("#dashboard-row-1").css('display', theState);
- });