简体   繁体   中英

Pushing elements into array as copy

In prototypejs, why does the following code remove the matching divs from the #test div?

What confuses me is that this happens when they are being inserted in the #droparea, and not when they are being pushed in the array.

<div id="test">
    <div class="foo" id="22.1234">
        1
    </div>
    <div class="foo" id="22.1235">
        2
    </div>
    <div class="foo" id="53.2345">
        3
    </div>
    <div class="foo" id="53.2346">
        4
    </div>
</div>

<div id="droparea">

</div>

js

var elArray = [];
var els = $('test').select('.foo');

els.each(function(x){ if(x.id.split('.')[0] == 22){ elArray.push(x); } });
elArray.each(function(y){ $('droparea').insert({ bottom: y }); });

I take it you want to copy/clone the elements into the drop area, not move them?

This thread on Google Groups discusses how to clone an element . Note in particular the caveats about changing the ID before reinserting to the document.

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