# レコード詳細画面の文字色と背景色の変更

**URL:** <https://community.cybozu.dev/t/topic/6080>\
**Category:** kintone 開発相談\
**Created:** [June 17, 2022, 9:49am UTC](https://community.cybozu.dev/t/topic/6080 "2022-06-17T09:49:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account1856](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@Legacy\_Account1856](https://community.cybozu.dev/u/Legacy_Account1856)\
**Post date:** [June 17, 2022, 9:49am UTC](https://community.cybozu.dev/t/topic/6080/1 "2022-06-17T09:49:49Z")

</div>

レコード詳細画面の特定の文字に色をつけたいです。

下記サイトを見て、  
[https://developer.cybozu.io/hc/ja/articles/202341944-%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E4%B8%80%E8%A6%A7%E3%81%A8%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E8%A9%B3%E7%B4%B0%E7%94%BB%E9%9D%A2%E3%81%A7%E6%9D%A1%E4%BB%B6%E6%9B%B8%E5%BC%8F%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B](https://developer.cybozu.io/hc/ja/articles/202341944-%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E4%B8%80%E8%A6%A7%E3%81%A8%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E8%A9%B3%E7%B4%B0%E7%94%BB%E9%9D%A2%E3%81%A7%E6%9D%A1%E4%BB%B6%E6%9B%B8%E5%BC%8F%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B)  
「チェックボックス」の文字の色は変更できたのですが、  
「文字列（１行）」の文字の色変更ができません。

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
「文字列（１行）」で色変更できず  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
&nbsp; &nbsp; // レコード詳細画面の表示時にフィールド値に応じて文字色を変更する

&nbsp; &nbsp; (function() {  
&nbsp; &nbsp; &nbsp; &nbsp; ‘use strict’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kintone.events.on(‘app.record.detail.show’, function(event) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var elUrgent = kintone.app.record.getFieldElement(‘Urgent1’);  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (event.record[‘Urgent1’][‘value’][0] === “赤字にしたい”) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elUrgent.style.color = ‘#ff0000’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elUrgent.style.fontWeight = ‘bold’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }})  
&nbsp; &nbsp; })();  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
「チェックボックス」の文字の色は２つ試して変更できました  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
&nbsp; &nbsp; (function() {  
&nbsp; &nbsp; &nbsp; &nbsp; ‘use strict’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kintone.events.on(‘app.record.detail.show’, function(event) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var elUrgent = kintone.app.record.getFieldElement(‘Urgent2’);  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (event.record[‘Urgent2’][‘value’][0] === “青字にしたい”) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elUrgent.style.color = ‘#0000ff’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elUrgent.style.fontWeight = ‘bold’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }})  
&nbsp; &nbsp; })();

&nbsp; &nbsp; (function() {  
&nbsp; &nbsp; &nbsp; &nbsp; ‘use strict’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kintone.events.on(‘app.record.detail.show’, function(event) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var elUrgent = kintone.app.record.getFieldElement(‘Urgent3’);  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (event.record[‘Urgent3’][‘value’][0] === “緑字にしたい”) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elUrgent.style.color = ‘#008000’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elUrgent.style.fontWeight = ‘bold’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }})  
&nbsp; &nbsp; })();  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

また、ボックス内の背景も黄色などに変更したいです。下記サイトを見て出来そうな気がしたのですが…  
[https://developer.cybozu.io/hc/ja/community/posts/360040458632-%E5%85%A5%E5%8A%9B%E3%83%95%E3%82%A3%E3%83%BC%E3%83%AB%E3%83%89%E3%81%AB%E8%89%B2%E3%82%92%E3%81%A4%E3%81%91%E3%81%9F%E3%81%84](https://developer.cybozu.io/hc/ja/community/posts/360040458632-%E5%85%A5%E5%8A%9B%E3%83%95%E3%82%A3%E3%83%BC%E3%83%AB%E3%83%89%E3%81%AB%E8%89%B2%E3%82%92%E3%81%A4%E3%81%91%E3%81%9F%E3%81%84)

「var parent = document.getElementById(“record-gaia”);」  
の「record-gaia」の変更は、  
F12でcopy elementすると…、  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\<div class=“control-gaia control-single\_line\_text-field-gaia field-6384723 control-show-gaia” style=“box-sizing: border-box; width: 193px; height: auto;”\>\<div class=“control-value-gaia value-6384723”\>\<span class=“control-value-content-gaia”\>赤字にしたい\</span\>\</div\>\<div class=“control-design-gaia”\>\</div\>\</div\>  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
と出てきて、どこを抜き出すのか分かりません。。。

「var nodes = parent.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0];」  
は0か1を変えればいいとのことですが、どこをどう変えてよいのか、理解できず。。。

&nbsp;

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2229](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@Legacy\_Account2229](https://community.cybozu.dev/u/Legacy_Account2229)\
**Post date:** [June 18, 2022, 2:13pm UTC](https://community.cybozu.dev/t/topic/6080/2 "2022-06-18T14:13:10Z")

</div>

Ichiro Saitoさん

こんにちは。

&nbsp;

文字列1行の場合は[‘value’]までの指定です。

背景色も同じようにstyleで指定できます。

```
kintone.events.on('app.record.detail.show', function(event) {
  var elUrgent = kintone.app.record.getFieldElement('Urgent1');
  if (event.record['Urgent1']['value'] === "赤字にしたい") {
        elUrgent.style.color = '#ff0000';
        elUrgent.style.fontWeight = 'bold';
      elUrgent.style.backgroundColor = '#0000ff'; // 背景色
    }
});

```

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1856](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@Legacy\_Account1856](https://community.cybozu.dev/u/Legacy_Account1856)\
**Post date:** [June 21, 2022, 3:17am UTC](https://community.cybozu.dev/t/topic/6080/3 "2022-06-21T03:17:39Z")

</div>

koichiさま

&nbsp;

できました！

[0]が要らなかったんですね。一人では辿り着けませんでした！！

&nbsp;

ありがとうございました！！！

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/cybozu/original/1X/d5c841c3c5a6cb66eed514001c1b45147c9e1f4f.png) [@system](https://community.cybozu.dev/u/system)\
**Post date:** [September 10, 2024, 4:25am UTC](https://community.cybozu.dev/t/topic/6080/4 "2024-09-10T04:25:53Z")

</div>

Closed on September 10, 2024, 4:25am UTC

このトピックはベストアンサーに選ばれた返信から 3 日が経過したので自動的にクローズされました。新たに返信することはできません。
