Hey there! I'm currently working on implementing a feature where, upon clicking "show more", 3 images will be displayed. And if the user clicks again, another set of 3 images will appear, and so on. I seem to be facing some difficulties with the JavaScript part of it. Any help in identifying the error would be greatly appreciated.
You can find my code on fiddle here
$(document).ready(function () {
image_x = $(".handler .col-md-4").size();
x=1;
$('.handler .col-md-4:lt('+x+')').show();
$('#loadMore').click(function () {
x= (x+5 <= image_x) ? x+1 : image_x;
$('.handler .col-md-4:lt('+x+')').show();
});
$('#showLess').click(function () {
x=(x-5<0) ? 3 : x-5;
$('.handler .col-md-4').not(':lt('+x+')').hide();
});
});
.col-md-4 {
width: 100%;
text-align: center;
}
.col-md-6 {
width: 100%;
text-align: center;
}
#loadmore {
border: 1px solid;
padding: 20px;
}
#loadless {
border: 1px solid;
padding: 20px;
}
<div class="handler">
<div class="col-md-4">
<div class="livery-article">
<a href="/blogs/good-company/72810435-hello-america">
<img class="livery-article-image"
src="http://cdn.shopify.com/s/files/1/0893/1740/files/blog1_large.png?16108356891554572192">
</a>
</div>
</div>
<br />
<div class="col-md-4">
<div class="livery-article">
<a href="/blogs/good-company/72810435-hello-america">
<img class="livery-article-image"
src="http://cdn.shopify.com/s/files/1/0893/1740/files/blog1_large.png?16108356891554572192">
</a>
</div>
</div>
<br />
<div class="col-md-4">
<div class="livery-article">
<a href="/blogs/good-company/72810435-hello-america">
<img class="livery-article-image"
src="http://cdn.shopify.com/s/files/1/0893/1740/files/blog1_large.png?16108356891554572192">
</a>
</div>
</div>
<br />
<div class="col-md-4">
<div class="livery-article">
<a href="/blogs/good-company/72810435-hello-america">
<img class="livery-article-image"
src="http://cdn.shopify.com/s/files/1/0893/1740/files/blog1_large.png?16108356891554572192">
</a>
</div>
</div>
<br />
</div>
<br />
<br />
<div class="col-md-6">
<a href="#" id="loadmore">show more image</a>
<a href="#" id="loadless">show more image</a>
</div>
<br />
<br />
<br />
<br />
<br />
<br />