Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery - moving li element out of the parent ul, and retaining position
    primarykey
    data
    text
    <p>I need to move li element out of its parent ul and into master parent ul.</p> <p>I tried this:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $( init ); function init() { // Move $('ul#listcomments').append( $('.children&gt;li') ); // Delete $('.children').remove(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;ul id="listcomments"&gt; &lt;li&gt;Comment 1&lt;/li&gt; &lt;li&gt;Comment 2&lt;/li&gt; &lt;li&gt;Comment 3&lt;/li&gt; &lt;li&gt;Comment 4&lt;/li&gt; &lt;li&gt;Comment 5 &lt;ul class="children"&gt;&lt;li&gt;Child comment of #5 is this&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt; &lt;li&gt;Comment 6&lt;/li&gt; &lt;li&gt;Comment 7&lt;/li&gt; &lt;li&gt;Comment 8&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I want to achieve this: * that is, make child li#5child to get out of ul and li and appear right below li.</p> <pre><code>&lt;ul id="listcomments"&gt; &lt;li&gt;Comment 1&lt;/li&gt; &lt;li&gt;Comment 2&lt;/li&gt; &lt;li&gt;Comment 3&lt;/li&gt; &lt;li&gt;Comment 4&lt;/li&gt; &lt;li&gt;Comment 5&lt;/li&gt; &lt;li&gt;Child comment of #5 is this&lt;/li&gt; &lt;li&gt;Comment 6&lt;/li&gt; &lt;li&gt;Comment 7&lt;/li&gt; &lt;li&gt;Comment 8&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Instead I get: * append drops li outside, but puts it at the very end of ul#listcomments</p> <pre><code>&lt;ul id="listcomments"&gt; &lt;li&gt;Comment 1&lt;/li&gt; &lt;li&gt;Comment 2&lt;/li&gt; &lt;li&gt;Comment 3&lt;/li&gt; &lt;li&gt;Comment 4&lt;/li&gt; &lt;li&gt;Comment 5 &lt;/li&gt; &lt;li&gt;Comment 6&lt;/li&gt; &lt;li&gt;Comment 7&lt;/li&gt; &lt;li&gt;Comment 8&lt;/li&gt; &lt;li&gt;Child comment of #5 is this&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I hope this explains it better than using words. It's pretty simple as a concept, but with my limited skills, I couldn't come up with anything better.</p> <p>help! :)</p> <p>*notice: naming and numbering of lis is arbitrary. And child comment can appear within any # li. Content is dynamically generated.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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