+ 2
Why Variable dont get recongnized
I dont know why my variable div1E is difined with null? https://code.sololearn.com/WK48OH3pOJKM
4 Respuestas
+ 4
jack,
The reason why your code behave like that is cause SoloLearn implementing their JS in the head, Therefore you need to use window.onload to the whole DOM functionallity and not only the part of the addEventListener.
Hope this helps out👍
Solution to your issue:
https://code.sololearn.com/WkU772IJ3gBP/?ref=app
+ 1
thanks a lot
+ 1
I’ve noticed a few things with your code;
1. When using addEventListener, don’t include parentheses (“()”) with your function call - i.e.
div1E.addEventListener(“click”, addchildren, false);. My knowledge of JS is very limited and there may be situations where you would put arguments in these types of function calls but, for now, I’d advise you omit them until you can do more research into them.
2. Using “el” as your function parameter is fine, however, if you are using it to refer to the element that is clicked, you need to use “el.target”. You can precede those statements with
var el = el.target;
3. Line 22; el.removeChild(div1E.lastChild); - where one of the “hallo” text nodes are clicked, it tries to remove the last child of the text node, of which there are no children, so it also throws an error here.
Hope this helps!
0
now i have a second question i want to open and close the diverent childs of the element.
like automaticaly generate a child with a click and close it with a click but its not working.
it prints infinitif times hello instead of waiting for my click
https://code.sololearn.com/Wf75ORrUUK2w