Reputation: 47
I need to add if and else in the JS file, I have the following variable '+item.is_withdraw+'
that outputs 1 or 0. And I need to do if ('+item.is_withdraw+' === 1) {<span class="comission">Online</span>} else {}
if the answer is 0, do not show anything.
My code:
$('.invent-main').append('<div id="item" title="'+item.market_hash_name+'" data-id="'+item.assetid+'" data-price="'+item.price+'" onclick="Inventory.selectItemInventory('+item.assetid+')" class="rarity-'+item.type+'">\n' +
' <img src="https://steamcommunity-a.akamaihd.net/economy/image/'+item.classid+'/60fx60f" class="invent-item">\n' +
' <div class="item-bottom">'+item.is_withdraw+' \n' +
' <div class="item-bottom-l">\n' +
' '+item.price+'\n' +
' </div>\n' +
' <div class="item-bottom-r">\n' +
' <i class="fa fa-rub" aria-hidden="true"></i>\n' +
' </div>\n' +
' </div>\n' +
'</div>');
});
How i can do it?
Upvotes: 0
Views: 57
Reputation: 1933
You can do it with ternary operator:
<div class="item-bottom">'+(item.is_withdraw === 1 ? '<span class="comission">Online</span>' : '')+' \n' +
Upvotes: 3