+ 2
Please why am i getting the erro? Why is my clare function not working?
18 Answers
+ 1
daneillonge I believe youāre right in saying that āeā is the event, which in this is āclickā but can be something like a mouseover or keyup for example.
e.target is the button here. This can be seen by adding the line:
console.log(e.target.nodeName);
...into the clare function.
+ 6
There is more than one problem in your code... See here for commented solution
https://code.sololearn.com/W946UeLUdXke/?ref=app
+ 4
You don't have an elememt with the id "input"... Add id="input" to your input element to correct.
+ 3
Use document.getElementById('but') and not getElementsByTagName('but')
+ 2
KrOW thanks
+ 2
your code is beautiful but little messy make it clean if you doing complex programming in future
+ 2
remember if val != emty string then val must be equal to element making output inside element you created
+ 2
for simple understanding e is the button and target is pointing the parent node li which is the parent of of button to remove the child
+ 2
correct me if im wrong e is the vent right anything we do on webpage like clicking and the function is perform
+ 1
SOrry but i dont see your Clare function... Can you point better to your code/problem?
+ 1
The problem is that line 39 returns an array to variable ābutā. You canāt directly add an onclick function to that array, you need to add it to each element of that array.
for (var i=0; i<but.length; i++){
but[i].onclick = function clare(e){
mylist.removeChild(e.target.parentNode);
}
}
+ 1
Thanks Russ
+ 1
i can see it clear if i console.log(e) it return the object mouse event it makes it clear.
0
https://code.sololearn.com/WmIM92znN3uW/?ref=app I solve your problem
0
KrOW
please help me check it my Clare function not working
0
Russ thanks sir but why the argument in the function clare(e) and please expline this lines of code mylist.removeChild(e.target.parentNode). it worked but am confused
0
I am by no means an expert at this, but I will try and explain the way I understand it. Hopefully others with more knowledge than me will correct me where Iām wrong.
The āeā in the clare(e) function definition refers to the action that triggers the function call (in this case, āclickā). I believe you can use almost anything instead of e, but e is widely used and understood.
In the āe.target.parentNodeā part, the e.target refers to the ātargetā of the action which, in this case, is the x button that gets clicked.
The reason that āparentNodeā is required is down to the way you have constructed your code. You have created an āliā element and appended your button to it. This means that the button is a āchildā of your li element. Since the button is the e.target and the li is what you want to remove, you need to remove the buttonās parent node, hence e.target.parentNode.
Hope this makes sense.



