# Javascript code for text color and background color

**URL:** <https://forums.knack.com/t/javascript-code-for-text-color-and-background-color/9941>\
**Category:** Get Answers\
**Created:** [June 11, 2018, 11:01am UTC](https://forums.knack.com/t/javascript-code-for-text-color-and-background-color/9941 "2018-06-11T11:01:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guilhermeb42087](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@Guilhermeb42087](https://forums.knack.com/u/Guilhermeb42087)\
**Post date:** [June 11, 2018, 11:01am UTC](https://forums.knack.com/t/javascript-code-for-text-color-and-background-color/9941/1 "2018-06-11T11:01:30Z")

</div>

Hi Everyone,

Does anyone have a javascript code to let me change text and background color and a record is = to x (something)?

Thanks!

---

<div class="post-metadata">

**Author:** ![JulianKirkness](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/juliankirkness/32/770_2.png) [@JulianKirkness](https://forums.knack.com/u/JulianKirkness)\
**Post date:** [June 11, 2018, 3:38pm UTC](https://forums.knack.com/t/javascript-code-for-text-color-and-background-color/9941/2 "2018-06-11T15:38:05Z")

</div>

It is possible to do this based on connected objects up to a point - you just have to have a Text Formula or Equation field in the record to pull the information into your table via the connection.

---

<div class="post-metadata">

**Author:** ![Sunny\_Singla](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/sunny_singla/32/1007_2.png) [@Sunny\_Singla](https://forums.knack.com/u/Sunny_Singla)\
**Post date:** [June 11, 2018, 2:28pm UTC](https://forums.knack.com/t/javascript-code-for-text-color-and-background-color/9941/3 "2018-06-11T14:28:43Z")

</div>

Hi,

&nbsp;

Yes you can use below JQuery Code to do that

&nbsp;

var item ;  
$(document).on('knack-view-render.view\_xyx', function (event, scene) {  
 var data = Knack.models['view\_xyz'].data.models;  
 for (x = 0; x \< data.length; x++) {  
 item = data[x].attributes;  
 if(item.field\_123=="Conditions")  
{  
$("#"+item.id).css("background-color","#eee");

}  
 }  
});

&nbsp;

Regards,

Sunny Singla

[ssingla1985@gmail.com](mailto:ssingla1985@gmail.com)

---

<div class="post-metadata">

**Author:** ![Guilhermeb42087](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@Guilhermeb42087](https://forums.knack.com/u/Guilhermeb42087)\
**Post date:** [June 11, 2018, 11:13am UTC](https://forums.knack.com/t/javascript-code-for-text-color-and-background-color/9941/4 "2018-06-11T11:13:07Z")

</div>

I cant do that with connected objects as Knack doesnt have support at this moment. So I need to use custom javascript code to do the trick...

---

<div class="post-metadata">

**Author:** ![JulianKirkness](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/juliankirkness/32/770_2.png) [@JulianKirkness](https://forums.knack.com/u/JulianKirkness)\
**Post date:** [June 11, 2018, 11:09am UTC](https://forums.knack.com/t/javascript-code-for-text-color-and-background-color/9941/5 "2018-06-11T11:09:41Z")

</div>

If I understand your meaning, you can already do this with Display rules (at least for Tables) - for example:

&nbsp;

Is done by setting the same display rule for each of the fields in the table:

&nbsp;

(I chose to leave the column with the edit button un coloured)
