<!-- Brands -->
<div class="brands">
<ul class="thumbnails">
<li class="span3"> <a href="#" class="thumbnail"> hello1 </a> </li>
<li class="span3"> <a href="#" class="thumbnail"> hello2 </a> </li>
<li class="span3"> <a href="#" class="thumbnail"> hello3 </a> </li>
<li class="span3"> <a href="#" class="thumbnail"> hello4 </a> </li>
<li class="span3"> <a href="#" class="thumbnail"> hello5 </a> </li>
<li class="span3"> <a href="#" class="thumbnail"> hello6 </a> </li>
<li class="span3"> <a href="#" class="thumbnail"> hello7 </a> </li>
<li class="span3"> <a href="#" class="thumbnail"> hello8 </a> </li>
</ul>
</div>
That's my html code and this is my jQuery code.
$(document).ready(function () {
$('.brands li').click(function () {
var index = $(this).index();
alert(index);
if (index < 4) {
alert('less than 4');
}
if (index > 4 && index < 8) {
alert('less than 8');
}
if (index > 8 && index < 12) {
alert('less than 12');
}
});
});
i'm trying to later on insert a new li after the 4th li if the li is less than the 4nth-child, and then insert an li after the 8th li if the le is less than the 8nth-child and so on. is there any way of simplifying the rather than having a lot of if statements?