My aim is to check a given ingredient for different attributes with an list of OR statements, but it returns an unexpected || error.
JavaScript
x
12
12
1
$(".ingredient.clicked").each(function() {
2
if (typeof $(this).attr("noAddedSugar") != "undefined")
3
|| (typeof $(this).attr("vegan") != "undefined")
4
|| (typeof $(this).attr("glutenfree") != "undefined")
5
{
6
$('#proba').text("Proba");
7
} else {
8
$('#proba').text("");
9
return false;
10
}
11
});
12
It works when I add and modify the variables individually, does not when I use OR. Any input would be appreciated.
Thanks!
Advertisement
Answer
JavaScript
1
2
1
if (typeof $(this).attr("noAddedSugar") != "undefined") || (typeof $(this).attr("vegan") != "undefined") || (typeof $(this).attr("glutenfree") != "undefined")
2
should be
JavaScript
1
2
1
if( (typeof $(this).attr("noAddedSugar") != "undefined") || (typeof $(this).attr("vegan") != "undefined") || (typeof $(this).attr("glutenfree") != "undefined") )
2