# スペースフィールドへのinnerHTML

**URL:** <https://community.cybozu.dev/t/topic/241>\
**Category:** kintone 開発相談\
**Created:** [2017 年 1 月 30 日午前 9:58 UTC](https://community.cybozu.dev/t/topic/241 "2017-01-30T09:58:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account329](https://avatars.discourse-cdn.com/v4/letter/l/ee59a6/32.png) [@Legacy\_Account329](https://community.cybozu.dev/u/Legacy_Account329)\
**Post date:** [2017 年 1 月 30 日午前 9:58 UTC](https://community.cybozu.dev/t/topic/241/1 "2017-01-30T09:58:22Z")

</div>

innerHTMLで書いたものが消えなくて困ってます。

何がおかしいのか教えてください。

■構造

ラジオボタンがON/OFFとあり、ONの時はtext＿１に文字が現れ

OFFの時にはtext1に文字が現れる。つまりラジオボタンによる表示の制御を行いたい。

■事象

ON/OFFを繰り返し行うと増殖（これはチュートリアルにのっていたやつですよね）

そして、ON⇔OFF時に相互に書いた文字が1度表示されると消えない

■サンプル（if文で分岐させています。setfieldshownは正常に動いているためif分は正常に動いています）

\>\>ON時

&nbsp; &nbsp; &nbsp; &nbsp; var text1 = document.createElement(‘text1’);

&nbsp; &nbsp; &nbsp; &nbsp; var text\_1 = document.createElement(‘text\_1’);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text1.innerHTML = ‘’;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text\_1.innerHTML = ‘あ’;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kintone.app.record.getSpaceElement(‘text1’).appendChild(text1);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kintone.app.record.getSpaceElement(‘text\_1’).appendChild(text\_1);

\>\>OFF時

&nbsp; &nbsp; &nbsp; &nbsp; var text1 = document.createElement(‘text1’);

&nbsp; &nbsp; &nbsp; &nbsp; var text\_1 = document.createElement(‘text\_1’);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text1.innerHTML = ‘い’;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text\_1.innerHTML = ‘’;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kintone.app.record.getSpaceElement(‘text1’).appendChild(text1);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kintone.app.record.getSpaceElement(‘text\_1’).appendChild(text\_1);

&nbsp;

恐れ入りますがご助言くださいます様お願い致します。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2115](https://avatars.discourse-cdn.com/v4/letter/l/e9bcb4/32.png) [@Legacy\_Account2115](https://community.cybozu.dev/u/Legacy_Account2115)\
**Post date:** [2017 年 1 月 31 日午前 1:41 UTC](https://community.cybozu.dev/t/topic/241/2 "2017-01-31T01:41:17Z")

</div>

An.Ag さん  
cstapの瀧ヶ平です

要素を追加する際、各スペース要素の中身を消さずに新しく作成した要素を追加しているのが原因かと思います。

単純に要素の中身を消すだけなら

```
kintone.app.record.getSpaceElement('text1').innerHTML = "";

```

とすれば削除できます。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account329](https://avatars.discourse-cdn.com/v4/letter/l/ee59a6/32.png) [@Legacy\_Account329](https://community.cybozu.dev/u/Legacy_Account329)\
**Post date:** [2017 年 1 月 31 日午前 2:06 UTC](https://community.cybozu.dev/t/topic/241/3 "2017-01-31T02:06:52Z")

</div>

cstap 瀧ヶ平さん

&nbsp;

ありがとうございます！

まさにこれがやりたかったんです！

とても助かりました！

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