Variable Scope in document.ready() function
Dear Friends, I following codes where I have setup a global variable but its value is not getting updated within the flow. Code is below. Please guide me to find a solution:
var flgBtnBold;
$(document).ready(function()
{
flgBtnBold=0;
$('#btnBold').click(function()
{
if(flgBtnBold==1)
{
alert('within if block when true');
$(this).css("color","#000");
flgBtnBold=0;
alert(flgBtnBold);
}
else
{
alert('within if block when false');
$(this).css("color","#f00");
flgBtnBold=1;
alert(flgBtnBold);
// It is giving output 1 as intended.
}
});
alert(flgBtnBold);
// It is giving output 0 instead of 1
});