At this website, I have a unique "status tag" (such as Diesel, Auto, Manual, etc) displayed on each inventory picture. I am looking to dynamically change the background color of the tag based on the text within the DIV element.
Below is the code snippet that I currently have:
<script>
$(function() {
var text = $('.image-container>.status-tag').text().toLowerCase(), color;
switch (text) {
case 'Diesel':
color = '#ff0000';
break;
case 'AUTO':
color = '#6dc8bf';
break;
default:
color = '#39d52d';
}
$('.image-container>.status-tag').css('background', color);
});
</script>
Despite setting the colors, only the default color is appearing on the site. I have tried implementing the code but haven't been successful in achieving the desired result based on the text content.
This code was sourced from a different post (original code here) and adapted for my website, but I seem to be experiencing some issues in making it work correctly. Any assistance in resolving this matter would be greatly appreciated.