title: Check variable true with if statement
body: <p>Here is my code:</p>
  
  <pre><code>$(val1).mouseleave(function () {
      flag = false;
      $(val3 + "," + val4).mouseenter(function () {
  
          flag = true;
          //alert(flag);
  
      });
      if (flag == true) {
          //alert("if"+flag);
          $(".big" + i + j + "boxer").show();
          $(".big" + i + "box").show();
          $(".big" + i + "box").append('&lt;div class="opacity" style="background-color:rgba(00,00,00,0.77);position:absolute;top:0;right:0;left:0;bottom:0;"&gt;&lt;/div&gt;')
          $(".small" + i + "box").append('&lt;div class="opacity" style="background-color:rgba(00,00,00,0.77);position:absolute;top:0;right:0;left:0;bottom:0;"&gt;&lt;/div&gt;')
  
      } else {
          //alert("else"+flag);
          $('.opacity').remove();
          $(val2).hide();
          $(val3).show();
  
      }
  });
  </code></pre>
  
  <p>It's not meeting <code>flag = true</code> condition. If I <code>alert</code> within <code>$(val1).mouseleave(function(){});</code>,  it shows that  <code>flag = true</code>; but when I alert it outside of <code>$(val1).mouseleave(function(){});</code>,  it shows <code>flag = false</code>.</p>
  
  <p>Well, let me explain: I have 4 blocks <code>val1,val2,val3</code> and <code>val4</code>. When the users leave <code>val1</code> and enter the <code>val3</code> or <code>val4</code> block, I want to <code>set/add opacity class</code> ... if they <code>do not enter</code> into <code>val3/val4</code> but <em>go</em> into <code>val2 or another block</code> block then I want to remove opacity class.</p>