I am working on a filter button / category feature that uses ajax, it will return the matching results. There are 4 results per row. I would like wrap the first 4 results and then every other 4 results with <div class="row"></div>
Everything works except I am having trouble figuring out how to wrap every 4 results with the row div. It is putting <div class="row"></div> in between every 4 results versus wrapping them.
Note: There will not always be an even multiple of 4 results, there may be something like 3 results or 7 results.
Update: I found out what was happening thanks to Jquery function closing div on append by itself
Basically you can not append a partial div, it will add </div> to the end.
success: function(data){
$('.beats').html('');
window.count = 0;
$('.beats').append('<div class="row">');
$.each(data, function(index, item) {
//console.log(item);
count++;
//console.log(count);
$('.beats').append('<div class="col-md-3 col-sm-6"><a href="#" class="track"><img src="image" alt="waves" class="img-responsive center-block"><span>name<span>keywords</span></span></a></div>');
if(count == 4){
$('.beats').append('</div> <div class="row">');
window.count = 0;
}
});
$('.beats').append('</div>');
//$('.beats').html('');
//console.log(starttype);
//console.log(data);
}
});
You can not append a partial div, it will auto-complete it. I found you can store the data as a string variable and then convert it to html at end like so:
I found out what was happening thanks to Jquery function closing div on append by itself.