Used below HTML & JS code for below requirement.
- Show first 3 divs, hide rest.
- Hide Load more button if less than 3 divs (as per data-show) otherwise show.
- On clicking load more button show another 3 (as per data-show value). show/hide load more button based on item exists.
- Show load more button still item exists. otherwise hide load more button.
var dataShow = $('.main-wrapper').attr('data-show');
var getEle = $('.main-wrapper').find('.ele');
if (getEle.length <= dataShow) {
$('.load-more').hide();
} else {
$('.load-more').show();
}
let getEleLength = $('.ele').length;
let showItems = dataShow - 1;
//$('.ele').slice(0, 3).show();
$('.ele:gt(' + showItems + ')').hide();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="main-wrapper" data-show="3">
<div class="ele">1</div>
<div class="ele">2</div>
<div class="ele">3</div>
<div class="ele">4</div>
<div class="ele">5</div>
</div>
<button class="load-more">Load more</button>