Hi all,
I am trying to write some code that empties an element using DOM methods, but it doesnt seem to be working.
Page: http://chris.unigliding.co.uk/weatherjack/index.php
Code In Question:
This is the behaviour I get:Code://Empty the element alert(eleFeedbackMsg.childNodes.length + " children in this node"); for (i = 0; i < eleFeedbackMsg.childNodes.length; i++) { alert("Removing Child " + i + " => " + eleFeedbackMsg.childNodes[i].nodeName); eleFeedbackMsg.removeChild(eleFeedbackMsg.childNodes[i]); }//for
Click the 'Place Votes!' button, you get the IMG and the text. Behaving well so far. Messages '1 Child' and 'Removing child 0: #text', as expected (it starts off with ' ' in there).
Click it again, you get the message '2 children', and then 'removing child 0: IMG'. It then removes the image, and adds another image / text. You now have 2x text, and 1x image.
Click it a third time, you get '3 children', and 'removing child 0: #text', then 'removing child 1: #text', which it does. Then puts in another image and another text, so you now have 2x IMG and 1x text.
Every time after that, it removes an IMG and the text, then just replaces it.
Can anyone tell me why it doesn't remove the last node, unless it's the only node in the first place? Also, the first time it seems to remove the only node (Correct), the 2nd time it ignores the last node (the text), and the 3rd time it seems to ignore the MIDDLE node, and remove the 2 text ones, which are the first and last one. You could actually say it ignores the 2nd element every time.
Any help would be greatly appreciated, I am fairly new to DOM methods / scripting!






Bookmarks