Note that there are some explanatory texts on larger screens.

plurals
  1. POAppend to dynamic element?
    text
    copied!<p>I have records from a database which contains parent-child data for each record. I'm attempting to create a parent-child list, but I'm having problems creating the child lists:</p> <pre><code>$(document).ready(function() { var objCategories = new Object ({ id: 0 }); $('#load-structures').click(function(event) { event.preventDefault(); objCategories.id = $(this).attr("data-category"); categories(); }); function categories() { $(".flash").show(); $(".flash").fadeIn(400).html("Loading..."); $.ajax({ url: base_url + "notes/jq_get_structures/" + objCategories.id, contentType: "application/json; charset=utf-8", dataType: "json", cache: false, success: function (element) { $(".flash").hide(); $(".load-link").addClass("link-none"); for (var i=0;i&lt;element.length;i++) { if (element[i].parent == 0) { $("#links-structures-parents").append('&lt;li id="structure-parent-' + element[i].structure_id + '"&gt;&lt;a href="#structures" title="View ' + element[i].name + '" class="structures"&gt;&amp;lsquo;' + element[i].name + '&amp;rsquo;&lt;/a&gt;&lt;/li&gt;'); } else if (element[i].parent &gt; 0) { if ($('#structure-children-' + element[i].structure_id).length) { $("#structure-children-" + element[i].structure_id).append('&lt;li id="structure-child-' + element[i].structure_id + '"&gt;&lt;a href="#structures" title="View ' + element[i].name + '" class="structures"&gt;&amp;lsquo;' + element[i].name + '&amp;rsquo;&lt;/a&gt;&lt;/li&gt;'); } else { $("#structure-parent-" + element[i].structure_id).html('&lt;ul id="structure-children-' + element[i].structure_id + '"&gt;'); $("#structure-parent-" + element[i].structure_id).html('&lt;li id="structure-child-' + element[i].structure_id + '"&gt;&lt;a href="#structures" title="View ' + element[i].name + '" class="structures"&gt;&amp;lsquo;' + element[i].name + '&amp;rsquo;&lt;/a&gt;&lt;/li&gt;'); $("#structure-parent-" + element[i].structure_id).html('&lt;/ul&gt;'); } } } }, error: function () { $("#links-structures-parents").empty(); $("#links-structures-parents").append('&lt;li&gt;There are no Structures.&lt;/li&gt;'); } } ); } }); </code></pre> <p>There are no problems with the data itself, but is instead the conditional part whereby I attempt to create the child lists.</p> <p>I have some <a href="http://jsfiddle.net/WayneSmallman/Vr6EU/8/" rel="nofollow">example code</a>, though for the life of me, I can't get it to run with the data locally, but I'm hoping someone knows what the trick is.</p>
 

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