So I am writing an app where color labels for images are loaded via Ajax. Let's say I request the labels for a certain images and the server returns a string with the colors. Each image container also contains four hidden divs in the respective colors with the classnames representing the colors...
<div class="red"></div> etc...
So I thought I split the string into an array, loop over it and set it to visible like so:
function attachLabel(obj,col)
...
$.ajax({
...
success:function(response){
//response contains an array of colors like red,green,blue,yellow
var cols=response.split(",");
for(var i=0;i<cols.length;i++) {
console.log(cols[i]);
obj.find("."+cols[i])[0].setAttribute('style','display:block')
}
},
});
}
Anyway this results in the following error, but only after exactly two colors have been set successfully:
Uncaught Error: Syntax error, unrecognized expression: .red
I really can't wrap my head around this... Any help would be appreciated...