Maarten Wolfsen Maarten Wolfsen - 5 months ago 9
jQuery Question

If statement not working after minimization

I had an if statement inside a scroll function, to check if the div

#homepage-flag
or the div
#landingspage-flag
exists. It was something like this:

$(window).scroll(function(e){
if($('#homepage-flag').length > 0 || $('#landingspage-flag').length > 0){
// code
}
});


I minified the code, but now the if statement only works for the div
#landingspage-flag
:

$("#homepage-flag").length > 0 || $("#landingspage-flag").length > 0 && $(window).scroll(function(l) {
// code
})

Answer

The minified code is completely wrong. The minified version should be something like :

$(window).scroll(function(g){$("#homepage-flag").length>0||$("#landingspage-flag").length>0});