($.cookie('cIDlist") is an array that looks like: 2, 0, 1, 2, 4.
The function works as intented but somehow the function imageToSlotNr() uses both the integer numbers and the commas as values. How do I get it to ignore the separating or commas or just remove the commas? And why is this even happening?
$("#vkorzinu").click(function(){
SLOTNUM = 1;
$.each($.cookie('cIDlist'), function(){
imageToSlotNr(this);
SLOTNUM++;
});
});
function imageToSlotNr(idnum){
if(SLOTNUM<9){
$("#slot"+SLOTNUM).css({"backgroundImage":"url('http://localhost/musli/"+idnum+"ingrid.png' )","background-size":"70px"});
} else {
alert("full");
}};
Your
$.eachis iterating over the characters in a string.You need to convert to an Array before iterating. Parsing it as JSON can be useful here.
If you want the numbers as strings, you can use
.split()instead of parsing it as JSON data.