views:

191

answers:

1

I'm trying to remove multiple nodes specified by checkboxes after a dojo fadeout. The nodes are simple HTML tr elements. There is an onclick event on a button that executes the below.

var tbody = dojo11.byId("resultBody1");
for (var k=0; k < selections.length; k++) {
    var temp = selections[k];              

    dojo11.fadeOut( {
        node:temp, 
        duration:1500,
        onEnd: function() {          
         tbody.removeChild(temp);          
        }      
    }).play();
}

It works fine for one node. If I select two or more nodes, it fadesOut all selected nodes in unison, but only removes the last selected node from the DOM tree while reporting errors for the first two.

Firebug console output:

exception in animation handler for: onEnd
Node was not found" code: "8
var _10b=null;\n

Any ideas how to remove all the selected nodes from the tree after the fadeOut?

A: 

This is actually a javascript closure issue. Fixed by closing off the current value of the indexed node each time the call is made to remove the node.

   for (var k=0; k < selections.length; k++) {
    var temp = selections[k];              

    dojo11.fadeOut( {
        node:temp,
        duration: 1500, 
        onEnd: function(node) {
          return function() {
          tbody.removeChild(node);
         }
        }(temp)                        
    }).play();