简体   繁体   中英

Remove child div when parent is selected again

I am using an n level selection chain using 99 points website tutorial , but when I try to reselect parent node, the corresponding child div isn't reset.

I have searched all over StackOverflow and Google, but so far no luck.

Error is with the following code and I am unable to correct it.

    $(this).nextAll('.parent').remove();
    $(this).nextAll('label').remove();

This is my code

Main Page

    <script type="text/javascript">
        $('.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));
        } 
    </script>

    <div id=levels>
        <select id="level" class="parent" multiple="multiple" scroabble="1" name="data[level][]">
<option value="Building & Construction Mat">Building & Construction Mat</option>
<option value="Electronic Components">Electronic Components</option>
<option value="Furniture & Mattresses">Furniture & Mattresses</option>
<option value="Labels">Labels</option>
</select>
    </div>

show_levels

    <select id="sublevel" class="parent" multiple="multiple" scroabble="1" name="data[sublevel][]">
<option value="Labels">Labels</option>
<option value="Preparation Techniques">Preparation Techniques</option>
<option value="Process Parameters">Process Parameters</option>
</select>

Update

Following code solved my problem

$("#levels").on('click', '.parent', function () {
    $(this).parents().nextUntil().remove();
});

you should remove the reference to the .livequery() plugin and use directly .live()

in this fiddle i've replicated the tutorial using the .live() functionality to show you how to use it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM