I have various products in which we list fields/properties in a list. Sometimes some of the properties are empty. When I try to hide these with jQuery, the fact that the li element contains the field name is causing the script not to execute.
How can I hide the entire li (in this case: barcode, notes) whilst the span fields are present?
$('ul li').each(function() {
if ($(this).text().length < 1)
$(this).hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="bookprofile">
<li class="barcode"><span style="color:#333;font-weight:bold">Barcode: </span></li>
<li class="bookauthor"><span style="color:#333;font-weight:bold">Book Author: </span>Entry</li>
<li class="format"><span style="color:#333;font-weight:bold">Format: </span>Entry</li>
<li class="pubdate"><span style="color:#333;font-weight:bold">Publication Date: </span>Entry</li>
<li class="publisher"><span style="color:#333;font-weight:bold">Publisher: </span>Entry</li>
<li class="notes"><span style="color:#333;font-weight:bold">Notes: </span></li>
<li class="rank"><span style="color:#333;font-weight:bold">Rank: </span>Entry</li>
</ul>