Pushing elements into array as copy

Posted by koko on Stack Overflow See other posts from Stack Overflow or by koko
Published on 2010-05-28T07:45:23Z Indexed on 2010/05/28 7:51 UTC
Read the original article Hit count: 208

Filed under:
|

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 }); });

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about prototype