On this site I have a "status tag" (Diesel, Auto, Manual, etc) on each inventory picture. I want the background color of that tag to be changed based on the text that is within the DIV.
This is the code that I have so far:
<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>
The default color is showing up, but for some reason, I cannot get the specified color to show based on the text inside the div.
This is not my own code, I found it on another thread(original code here), but can't seem to get it to work on my site. any help would be appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…