I'm making a non responsive site responsive. For the mobile view I'm trying to show 3 li elements on landing, click "show more" another 3 load and so forth. Hit show less and 3 li items should be removed.
I'm working on a project with a lot more li items but was wondering if the issue I am experiencing is a scope problem? And if there is a way to fix it.
The project I'm working on features a scrollable div displaying the li items in one div and hiding the rest until the user clicks an arrow. (this is why I havent rewritten the code from my predecessor original site is here to illustrate what I mean http://www.asla.org/sustainablelandscapes/index.html)
Is there a solution here?
I have recreated my issue (simplified) in a fiddle http://jsfiddle.net/gward90/xgmdkpb8/
EDIT: To further clarify, as seen with the fiddle all the li elements show on landing this should not be the case. Show less removes more than 3 items as well.
<div class="row">
<div class="col-md-12">
<ul class="thumbnails">
<li><div class="red"></div></li>
<li><div class="red"></div></li>
<li><div class="red"></div></li>
</ul>
</div>
</div>
<div class="row">
<div class="col-md-12">
<ul class="thumbnails">
<li><div class="blue"></div></li>
<li><div class="blue"></div></li>
<li><div class="blue"></div></li>
</ul>
</div>
</div>
<div class="row">
<div class="col-md-12">
<ul class="thumbnails">
<li><div class="green"></div></li>
<li><div class="green"></div></li>
<li><div class="green"></div></li>
</ul>
</div>
</div>
<div id="loadMore">Load more</div>
<div id="showLess">Show less</div>
$(document).ready(function () {
$('.thumbnails li:lt(3)').show();
$('#showLess').hide();
var items = 9;
var shown = 3;
$('#loadMore').click(function () {
$('#showLess').show();
shown = $('.thumbnails li:visible').size()+3;
if(shown< items) {$('.thumbnails li:lt('+shown+')').show();}
else {$('.thumbnails li:lt('+items+')').show();
$('#loadMore').hide();
}
});
$('#showLess').click(function () {
$('.thumbnails li').not(':lt(3)').hide();
});
});