Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You may want to use the DOM for this.</p> <p>Using <code>innerHTML</code> means having in-line HTML in your javascript. This breaks <a href="http://en.wikipedia.org/wiki/Separation_of_concerns" rel="nofollow">Seperations of concerns</a> and leads to maintenance hell.</p> <p><a href="http://jsfiddle.net/TeWv8/5/" rel="nofollow">Live Example</a></p> <pre><code>var createListFragment = (function () { function createItems(names,value,ids) { var namesArray = names.split(","); var valuesArray = value.split(","); var idsArray = ids.split(","); return namesArray.map(function (name, key) { return { name: name, value: valuesArray[key], id: idsArray[key] } }); } function createLi(item) { var itemLi = document.createElement("li"); itemLi.textContent = item.name; var propertiesUl = document.createElement("ul"); itemLi.appendChild(propertiesUl); var valueLi = document.createElement("li"); valueLi.appendChild(document.createTextNode("value: ")); var b = document.createElement("b"); b.textContent = item.value; valueLi.appendChild(b); propertiesUl.appendChild(valueLi); var idLi = document.createElement("li"); idLi.appendChild(document.createTextNode("id: ")); var b = document.createElement("b"); b.textContent = item.id; idLi.appendChild(b); propertiesUl.appendChild(idLi); return itemLi; } function createListFragment(names, values, ids) { var items = createItems(names, values, ids); var fragment = document.createDocumentFragment(); var h3 = document.createElement("h3"); h3.textContent = "items"; fragment.appendChild(h3); var ul = document.createElement("ul"); fragment.appendChild(ul); items.forEach(function (item) { var li = createLi(item); ul.appendChild(li); }); return fragment; } return createListFragment; })(); </code></pre> <p>You may need a <a href="https://github.com/Raynos/DOM-shim" rel="nofollow">DOM-shim</a> and <a href="https://github.com/kriskowal/es5-shim" rel="nofollow">ES5-shim</a> for cross browser compliance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload