I'm trying to add a color to filter options in my webshop. The color codes are getting saved, now I return them through json. What i'm trying to do is add the color code to the parent class above the input. I found out how to change the class name (which i need for other reasons), but now I must add the color codes in order that json returns them top, down.
Here's what I got so far:
function onDataReceived(data) {
for (var i = 0; i < data.colorInfo.length; i++) {
console.log(data.colorInfo[i].colorCode);
}
$('input[id^="filter_"]').each(function(){
$(this).parent().attr('class','addedClass');
$(this).parent().parent().attr('class','addedClass');
});
}
$(document).ready(function () {
var url = 'myjsonlink.json';
$.get(url, onDataReceived);
});
The line with console.log(data.colorInfo[i].colorCode); results in the 3 color codes i need #fff etc. Is there a way to insert each of the results above the 3 input types i have?
What i would like to achieve is:
<div style="background-color: data.colorInfo[i].colorCode"> <input> </div>
something like that