First thing I noticed is it seems to be short one parenthesis, and has an extra closing brace. I've tried various combinations to fix it and can't get it working.
If I put a closing paren after function (test_element) I get a warning it's expecting a { at that point. Nothing else even looks right.
[link|http://dkime.com/js_iterator.php|Here's] my sample code. If anyone can figure this out several of us here will be very grateful.