動的選択ボックスを作成しています。変更すると、テキスト セクションにデータが入力されます。追加するのではなく、データを何らかのテキストに設定したいと思います。
例えば:
この関数は、選択ボックスが変更されたときに呼び出されます。
function createDetails(...) {
var details = document.getElementById("detailsDIV");
var docFragment = document.createDocumentFragment();
containerDiv = document.createElement("div");
// Create five div sections with the text for the details section
var nameTextNode = createTextDivSect(nameStr);
var phoneTextNode = createTextDivSect("Phone: " + phoneStr);
var faxTextNode = createTextDivSect("Fax: " + faxStr);
var websiteTextNode = createTextDivSect("Website: " + websiteStr);
var emailTextNode = createTextDivSect("Email: " + emailStr);
// Append the text sections to the container DIV
containerDiv.appendChild(nameTextNode);
containerDiv.appendChild(phoneTextNode);
containerDiv.appendChild(faxTextNode);
// Add the container div to the doc fragment
docFragment.appendChild(containerDiv);
// Add the doc fragment to the div
details.appendChild(docFragment);
}
////
このアプローチでは、セクションに追加していると想定しています。子を設定する方法はありますか。子を削除してから設定できると思います。しかし、それはリソースを浪費すると思います。