Waqar Malik Waqar Malik - 2 months ago 7
jQuery Question

Not going to my second if condition, was just wondering why?

Code goes to second

else if n==1
however it does not go to my second
if n ==2
, was just wondering why? please see code below

$('.uploadmorefiles').click(function () {
debugger;
var n = $('.filediv:visible').length;
if (n == 4) {
$('.uploadmorefiles').hide();
}else {
if (n == 1)
$('.uploadsecfile').show();

{
if (n == 2)
alert("The paragraph was clicked.");

}
}

});

Answer

First I don't see a second else :)

I think your code should look like this:

$('.uploadmorefiles').click(function () {
  debugger;
  var n = $('.filediv:visible').length;
  if (n == 4) {
    $('.uploadmorefiles').hide();
  } else if (n == 1) {
    $('.uploadsecfile').show();
  } else if (n == 2) {
    alert("The paragraph was clicked.");
  }
});