Reputation: 1687
What is the syntax for this loop to skip over certain keys? The way I have it written is not working properly.
$.each(element, function(i, element_detail){
if (!(i == 'InvKey' && i == 'PostDate')) {
var detail = element_detail + ' ';
$('#showdata').append('<div class="field">' + i + detail + '</div>');
}
});
Upvotes: 30
Views: 248462
Reputation: 19
A more general approach:
if ( ($("body").hasClass("homepage") || $("body").hasClass("contact")) && (theLanguage == 'en-gb') ) {
// Do something
}
Upvotes: 0
Reputation: 6607
Try
if (!(i == 'InvKey' || i == 'PostDate')) {
or
if (i != 'InvKey' || i != 'PostDate') {
that says if i does not equals InvKey
OR PostDate
Upvotes: 60
Reputation: 887453
i == 'InvKey' && i == 'PostDate'
will never be true, since i
can never equal two different things at once.
You're probably trying to write
if (i !== 'InvKey' && i !== 'PostDate'))
Upvotes: 14