Reputation: 85
Im editing/creating the following script for my website.
As you can see below I want him to add a <div class="row">
at the start of every row. (Hard to explain).
Then with the var "getal" I want him to END this DIV tag after 4 items in it (4x the foreach loop)
But the way I'm trying to do it with the If loops is not working. Any ideas? (The code is working fine without the <div class="row">
, if loops and var getal.
function show_albums (response) {
var getal = 0;
//hide main loader
$('#loading_gallery').hide();
$.each(response.data, function(key, value) {
//create html structure
//rijen teller
if (getal = 0 ) {
var html = '<div class="row">';
$('#albums').append(html);
}
//albums
var html = '' +
'<div class="col-lg-3 col-md-3 col-xs-3 thumb" id="album_' + key + '"> ' +
'<a href="#" class="album_link_' + key + '"><img class="img-thumbnail" id="album_cover_' + key + '" /></a>' +
'<img id="loading_' + key + '" src="images/ajax-loader.gif" />' +
'<a href="#" class="album_link_' + key + '"><h2>' + value.name + '</h2></a>' +
'<p>' + value.count + ' foto's</p>' +
'</div>';
getal++;
if (getal = 4) {
var html = '</div>';
$('#albums').append(html);
getal = 0;
}
$('#albums').append(html);
}
}
Upvotes: 0
Views: 69
Reputation: 10924
You are using the assignment operator =
instead of the comparison operator ==
in your if
statements. Try replacing those.
Upvotes: 1