jquery - if else javascript statement always returns if? -


could 1 please explain why if statement in code returns true:

(function ($) {     //load on page load     $(".area").load("/galleries/ #projects > li a");      //load on widget title click     $('.widget-top').live("click", function () {         $(".area").load("/galleries/ #projects > li a");     });      //stop default href working     $('.area a').unbind().live("click", function () {         event.preventdefault();         return;     });      // variables     var = $('#widgets-right .addinput').size() + 1;     var adddiv = $('.addinput');     //dynamic forms        $('#widgets-right .addnew').live('click', function () {         $(this).parents('.addinput').append('<div class="div_' + + '"><h4>reference project ' + + '</h4><div class="gallery_one_image_wrap"><img class="gallery_one" src="" /><br/></div><p><label for="title' + + '">title:</label><input type="text" class="title' + + '" name="title' + + '" value="title' + + '" style="width:100%;" /></p><p><label for="name' + + '">the link:</label><input type="text" class="link' + + '" id="name' + + '" name="name' + + '" value="name' + + '" style="width:100%;" /></p><p><label for="img' + + '">the link image:</label><input type="text" class="img' + + '" id="img' + + '" name="img' + + '" value="img' + + '" style="width:100%;" /></p><a href="#" class="remnew">remove</a></div>');         i++;         alert(i);         return false;     });      $('#widgets-right .remnew').live('click', function () {         if (i > 1) {             $(this).parent('div').remove();             i--;             alert(i);         }         return false;     });      //load input boxes     if (i === 2) {          $("#widgets-right .area a").live("click", function () {             alert(i);             alert("this if ");             var title = $(this).attr('title');             $(".title").val(title);             var link = $(this).attr('href');             $(".link").val(link);             var img = $("img", this).attr('src');             $(".img").val(img);             var imgexample = $("img", this).attr('src');             $(".gallery_one").attr("src", imgexample);          });     } else {         alert("this else!");     }   }(jquery)); 

the if/else statement in question one:

//load input boxes if ( === 2){  $("#widgets-right .area a").live("click", function() {   alert(i); alert("this if ");           var title = $(this).attr('title');           $(".title").val(title);           var link = $(this).attr('href');           $(".link").val(link);           var img = $("img", this).attr('src');           $(".img").val(img);           var imgexample = $("img", this).attr('src');           $(".gallery_one").attr("src", imgexample);      }); }else{    alert("this else!") } 

whenever click on #widgets-right .area a goes if if above 2. why? chris

i think mean put if inside event handler:

$("#widgets-right .area a").live("click", function () {     if (i === 2) { 

the way have now, check execute once, when page loads.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -