+ 2

Please why am i getting the erro? Why is my clare function not working?

https://code.sololearn.com/WI7NNK57Oh25/?ref=app

8th Jan 2019, 8:24 AM
Reward
Reward - avatar
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.
12th Jan 2019, 7:41 AM
Russ
Russ - avatar
+ 6
There is more than one problem in your code... See here for commented solution https://code.sololearn.com/W946UeLUdXke/?ref=app
8th Jan 2019, 9:02 AM
KrOW
KrOW - avatar
+ 4
You don't have an elememt with the id "input"... Add id="input" to your input element to correct.
8th Jan 2019, 8:49 AM
Niwo
Niwo - avatar
+ 3
Use document.getElementById('but') and not getElementsByTagName('but')
10th Jan 2019, 1:08 PM
KrOW
KrOW - avatar
+ 2
KrOW thanks
8th Jan 2019, 9:28 AM
Reward
Reward - avatar
+ 2
your code is beautiful but little messy make it clean if you doing complex programming in future
9th Jan 2019, 12:31 AM
Dancode
Dancode - avatar
+ 2
remember if val != emty string then val must be equal to element making output inside element you created
9th Jan 2019, 12:34 AM
Dancode
Dancode - avatar
+ 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
12th Jan 2019, 2:34 AM
Dancode
Dancode - avatar
+ 2
correct me if im wrong e is the vent right anything we do on webpage like clicking and the function is perform
12th Jan 2019, 2:36 AM
Dancode
Dancode - avatar
+ 1
SOrry but i dont see your Clare function... Can you point better to your code/problem?
10th Jan 2019, 12:26 PM
KrOW
KrOW - avatar
+ 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); } }
10th Jan 2019, 12:50 PM
Russ
Russ - avatar
+ 1
Thanks Russ
11th Jan 2019, 11:32 PM
Reward
Reward - avatar
+ 1
i can see it clear if i console.log(e) it return the object mouse event it makes it clear.
14th Jan 2019, 3:38 AM
Dancode
Dancode - avatar
8th Jan 2019, 10:07 PM
Dima
Dima - avatar
9th Jan 2019, 7:45 PM
syed ahemed buhary
syed ahemed buhary - avatar
0
KrOW please help me check it my Clare function not working
10th Jan 2019, 12:02 PM
Reward
Reward - avatar
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
11th Jan 2019, 5:31 AM
Reward
Reward - avatar
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.
11th Jan 2019, 12:32 PM
Russ
Russ - avatar