htmlでinputとlabelの関連付けをした記述をすると画面上期待した動きになるのですが、javascriptで動的に要素を作成して関連付けを行うような処理を書いてみても画面上関連づいた動きをしてくれません。htmlとjavascriptの方で作られている要素は同じのはずなのですが、何が問題なのでしょうか?
html
1<div class="contents faq" id="que-div"> 2 <h2 id="cate1"></h2> 3 <input type="checkbox" id="chk1" class="on-off"> 4 <label for="chk1"></label> 5</div>
javascript
1//input 2_input = document.createElement('input'); 3_input.type = 'checkbox'; 4_input.id = 'chk1'; 5_input.className = 'on-off'; 6_div.appendChild(_input); 7 8//label 9_label = document.createElement('label'); 10_label.for = 'chk1'; 11_label.innerHTML = question; 12_div.appendChild(_label);

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/07 07:25
2017/04/07 07:30
2017/04/07 07:32
2017/04/07 07:36
2017/04/07 07:39