Change background-color with javascript

Hi everyone,

I'm trying to use javascript to change a background-color of a field when the record on it is "HABILITADOS".

Here is the code I'm trying to use, but something is not right. Can anyone help me to figure it out how to make it work?

$(document).on('knack-view-render.view_292', function(event, view, data) {
$("#view_292 > section > div:nth-child(2) > div:nth-child(1) > div > div > div.field_1062 > div > span > span").each(function() {
var backgroundColor = ($(this).find("span").text().trim() == "HABILITADOS") ? "#0ccf0c" : "#e80c9a";
$(this).css("backgroundColor", textColor);
})
});

Thanks!

Hi ,

 

Try to replace $(this).find("span").text().trim()  with $.trim($(this).find("span").text())

 

Thanks

Hi, were you ever able to resolve this? I would love to add a little background color to my groups.  Thanks.  Charlie