I am trying to show a div if the length of a string from a db call is not 0
So, to test, I’m trying:
html += '<div class="item_image"> price '+image.item_price;
Which will print within div item_image something like:
price $10
So, to show a div I want to because the price field is not empty I’m trying:
if(image.item_price.length>0){ // price
html += '<div class="price_holder">'+image.item_price+'</div>';
} // price
But it does not show the div, it’s as if it’s is not reading the length correctly, is there a better way to do this?
You can just check as
It will check for
undefined,empty stringandzero valueconditions. Javascript Truthy and Falsy conditions