I have a large list of items and I am interested in displaying only the first 3 items initially.
When a button is clicked, I want to reveal the hidden items. Rather than cutting off words mid-way as it currently does, I prefer to hide entire words that exceed the character limit.
An error message appears stating that jQuery(...).length is not a function.
jQuery(function () {
var maxLimit = 3;
var itemList = jQuery('.outer-card-expand li');
jQuery(itemList).each(function () {
var totalItems = jQuery(itemList).length();
if(totalItems.length > maxLimit) {
var beginning = totalItems.substr(0, maxLimit),
ending = totalItems.substr(maxLimit);
jQuery(this).html(beginning + '<span class="dots">...</span>')
.append(jQuery('<div class="see-more see-more-closed">').html(''))
.append(jQuery('<span class="hidden text-thats-hidden">').html(ending))
}
});
});
.hidden {
display: none!important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="outer-card-expand">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</div>