Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Created Nested Table Based on Attribute
    text
    copied!<p>So I asked a very similar question yesterday about nested lists thinking that I would be able to use the answer both for creating nested lists and nested tables. But when I try to modify the jQuery to created nested tables it goes a little haywire. Either it doesn't nest or it nests an entire table with the child <code>&lt;tr&gt;</code>'s under the parent <code>&lt;tr&gt;</code> instead of just the child <code>&lt;tr&gt;</code>'s. Sample tables:</p> <pre><code>&lt;table&gt; &lt;tbody&gt; &lt;tr id="10"&gt;&lt;td&gt;Parent 1&lt;/td&gt;&lt;/tr&gt; &lt;tr id="14"&gt;&lt;td&gt;Parent 2&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr class="10"&gt;&lt;td&gt;Child A&lt;/td&gt;&lt;/tr&gt; &lt;tr class="10"&gt;&lt;td&gt;Child B&lt;/td&gt;&lt;/tr&gt; &lt;tr Class="14"&gt;&lt;td&gt;Child X&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>(This jQuery is based on code that vzwick very graciously helped me with) The jQuery looks like this:</p> <pre><code>$('tbody.csTR_children tr').each(function() { probable_parent = $('tbody.csTR_parent tr#' + $(this).attr('class')); if (probable_parent.length) { if (!probable_parent.find('tbody').length) probable_parent.append('&lt;tbody/&gt;'); $(this).detach().appendTo(probable_parent.find('tbody')); } }); </code></pre> <p>This is the closest I get and it nests an entire table under each parent row (in IE it nests the first parent and child properly but the rest it doesn't), as I said above. Any suggestions?</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