Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove child div when parent is selected again
    primarykey
    data
    text
    <p>I am using an <em>n level selection chain</em> using <a href="http://www.99points.info/2010/12/n-level-dynamic-loading-of-dropdowns-using-ajax-and-php/" rel="nofollow">99 points website tutorial</a>, but when I try to reselect parent node, the corresponding child div isn't reset.</p> <p>I have searched all over StackOverflow and Google, but so far no luck.</p> <p>Error is with the following code and I am unable to correct it.</p> <pre><code> $(this).nextAll('.parent').remove(); $(this).nextAll('label').remove(); </code></pre> <p>This is my code</p> <p><em><strong>Main Page</em></strong></p> <pre><code> &lt;script type="text/javascript"&gt; $('.parent').livequery('change', function() { $(this).nextAll('.parent').remove(); $(this).nextAll('label').remove(); $.post("/dashboard/details/show_levels/", { parent_id: $(this).val(), }, function(response){ setTimeout("finishAjax('levels', '"+escape(response)+"')", 400); }); return false; }); }) function finishAjax(id, response){ //alert(unescape(response)); $('#'+id).append(unescape(response)); } &lt;/script&gt; &lt;div id=levels&gt; &lt;select id="level" class="parent" multiple="multiple" scroabble="1" name="data[level][]"&gt; &lt;option value="Building &amp; Construction Mat"&gt;Building &amp; Construction Mat&lt;/option&gt; &lt;option value="Electronic Components"&gt;Electronic Components&lt;/option&gt; &lt;option value="Furniture &amp; Mattresses"&gt;Furniture &amp; Mattresses&lt;/option&gt; &lt;option value="Labels"&gt;Labels&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; </code></pre> <p><strong>show_levels</strong></p> <pre><code> &lt;select id="sublevel" class="parent" multiple="multiple" scroabble="1" name="data[sublevel][]"&gt; &lt;option value="Labels"&gt;Labels&lt;/option&gt; &lt;option value="Preparation Techniques"&gt;Preparation Techniques&lt;/option&gt; &lt;option value="Process Parameters"&gt;Process Parameters&lt;/option&gt; &lt;/select&gt; </code></pre> <h2>Update</h2> <p>Following code solved my problem</p> <pre><code>$("#levels").on('click', '.parent', function () { $(this).parents().nextUntil().remove(); }); </code></pre>
    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.
 

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