I'm currently working on enhancing the filter options in my online store by incorporating color coding. I have successfully saved the color codes and now retrieve them through json. My goal is to add these color codes to the parent class above the input element. While I have managed to modify the class name as needed for other functionalities, I am now facing the challenge of arranging the color codes in the proper order when returned by json.
Here is an overview of my progress:
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 containing console.log(data.colorInfo[i].colorCode); displays the 3 necessary color codes like #fff, etc. Is there a way to insert each of these results above the 3 inputs I possess?
What I aim to accomplish is:
<div style="background-color: data.colorInfo[i].colorCode"> <input> </div>
Just like that!