cc young
cc young

Reputation: 20203

in javascript dom, removing all children yields error

using standard routine to remove all children in element

while( el.lastChild ) el.removeChild( el.lastChild );

yields: Uncaught Error: NOT_FOUND_ERR: DOM Exception 8

for( var i=el.children.length; i; i-- ) el.removeChild( el.children[i-1] );

yields same

routine works 99% of the time, but in one DIV errors out.

if it matters, focus is not in DIV.

any idea how to proceed?


Found problem.

On new code for INPUT type='number' where input and mouseout events created a change event so field would update correctly.

In some instances updating the item meant removing the row.

The problem was that, once the row was removed, the INPUT's focus was lost, thereby generating its own change event. When this event ran the row was still existent, but had lost the relationship to its parent. This generated the DOM Error 8 - not found.

Again, we have met the enemy, and they is us (thank you Pogo).

Upvotes: 1

Views: 607

Answers (1)

cc young
cc young

Reputation: 20203

Problem was triggers attempting to remove the row once an earlier trigger had already removed it. See description at bottom of question

Upvotes: 1

Related Questions