dom - Javascript .removeChild not working as expected -


i feel misunderstanding how .removechild works. have code here:

//organization string value gotten input node  if (organization == '') {     //there nothing in organization form     if (orgcontainer !== undefined) {         console.log(orgcontainer + ' exists , there nothing in organization form.');         //remove orgcontainer         orgcontainer.parentnode.removechild(orgcontainer);         console.log(orgcontainer + 'removed!');     } else {         console.log(orgcontainer + ' not exist , there nothing in organization form.')     } } else {     if (orgcontainer !== undefined || orgcontainer !== null) {         console.log(orgcontainer + ' exists , there in organization form.');     } else {         console.log(orgcontainer + ' not exist , there in organization form.')     } } 

basically when check page after calling orgcontainer.parentnode.removechild(orgcontainer) console log message of orgcontainer removed! when run function again says orgcontainer still exists though removed .removechild?

am misunderstanding how .removechild works? node gets removed parent node not cease exist or something? deleted dom not memory or something?

i wonderful console.log message undefined exists , there in organization form. .. what? how exist if it's undefined? i've read through documentation on developer.mozilla.org site still bit confused. appreciated, thanks!

your javascript variable still has reference node, , nothing in code attempts change that. take node out of dom, value of orgcontainer variable never changed.


Comments