Question: Im stuck, Im setting a variable when someone clicks, then testing with if to see if the variable exists and doing something else. Its a simple script which Im probably overthinking, would love someone's thoughts.

```
  $('.view-alternatives-btn').live('click', function() {

//$("#nc-alternate-wines").scrollTo();
   //$('.nc-remove').toggle();
   var showBtn = null;
   if (showBtn == null) {
   $('.view-alternatives-btn img').attr("src","../images/wsj_hide_alternatives_btn.gif");
   $('#nc-alternate-wines').show();
   showBtn = 1;
   console.log(showBtn);
   }
   else if (showBtn == 1) {
   $('.view-alternatives-btn img').attr("src","../images/wsj_view_alternatives_btn.gif");
   $('#nc-alternate-wines').hide();
   console.log("this " + showBtn);
   }
   return false; 
  });

```

Answer: 
You're *always* setting it to `null` when the button is clicked, so you'll never reach the `else if`...

You might instead use a global variable, or [`$.data()`](http://api.jquery.com/jQuery.data/)
First issue is that the variable `showBtn` is `local` to the function, so it gets re-defined each time you execute the script..  

Secondly you set its value right before checking it .. so it will always be set to `null`..

since you bind it with the `live` method which implies dynamic elements, i would use the [`.data()`](http://api.jquery.com/jQuery.data/) method.

```
$('.view-alternatives-btn').live('click', function() {

var showBtn = $(this).data('showBtn');
//$("#nc-alternate-wines").scrollTo();
   //$('.nc-remove').toggle();
   if ( showBtn ) {
   $('.view-alternatives-btn img').attr("src","../images/wsj_hide_alternatives_btn.gif");
   $('#nc-alternate-wines').show();
   $(this).data('showBtn',true);
   console.log(showBtn);
   }
   else{
   $('.view-alternatives-btn img').attr("src","../images/wsj_view_alternatives_btn.gif");
   $('#nc-alternate-wines').hide();
   console.log("this " + showBtn);
   }
   return false; 
  });

```