javascript - Node iterator failing when being used to instantiate objects -


i'm using javascript node iterator create instances of object attached elements within dom. following code i'm using , works fine:

var nodeiterator = document.createnodeiterator(     document.body,     nodefilter.show_element,     {         acceptnode: function(node) {             if (node.attributes['data-sd-autocomplete']                 && node.type === 'text')                 return nodefilter.filter_accept;         }     },     false ), nodelist = [], node;  sdautocomplete.fields = [];  while (node = nodeiterator.nextnode())     nodelist.push(node);  // add new instances of sdautocomplete fields list (var = 0; < nodelist.length; i++) {     sdautocomplete.fields.push(new sdautocomplete(nodelist[i])); } 

i tried shorten code make more concise, removing loop , replacing line within while loop directly instantiates node variable:

while (node = nodeiterator.nextnode())     sdautocomplete.fields.push(new sdautocomplete(node)); 

but causes page hang if while loop getting stuck. shed light on why case?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -