0

I want to delete a div with js using removeChild method but I must run the function twice why?

When I want to delete a child of a div object with js ,I must run my function twice.It seems like it had two text object in it whereas I put just one.Who knows about this issue?Why does it happen?

4th Apr 2019, 9:11 AM
Mahmood moridsadat zadeh
Mahmood moridsadat zadeh - avatar
6 odpowiedzi
+ 3
Because empty space in html code is also a child node called TextNode. The easy way is to leave no space between parent element and child element in the HTML code. The other way is to use children() instead of childNode()
4th Apr 2019, 1:31 PM
Gordon
Gordon - avatar
+ 3
What did Gordon mean was children, the ParentNode property.
4th Apr 2019, 3:43 PM
Calviղ
Calviղ - avatar
+ 3
Yes yes, should be children, no () sorry ~ Reference is Calvin's answer to my Q&A : https://www.sololearn.com/Discuss/1618304/?ref=app
4th Apr 2019, 4:12 PM
Gordon
Gordon - avatar
+ 2
Share your code please.
4th Apr 2019, 10:18 AM
Calviղ
Calviղ - avatar
+ 2
children() is only for jQuery it seems. Gordon
4th Apr 2019, 1:51 PM
Emoji FanBoy
Emoji FanBoy - avatar
+ 1
I tested the empty spaces and that is exactly correct.thank you Gordon
6th Apr 2019, 10:50 AM
Mahmood moridsadat zadeh
Mahmood moridsadat zadeh - avatar