+ 1
How to delete my items from the list?
Hello entrepreneurs. I'm stranded in a code. The code consists of adding elements to a list and then deleting each 'li' element with just a click on it. What am I failing at? For example I add three elements to my list, and I want to delete the second element but the first element is deleted, I want to delete the third element but the second element of the list is deleted. I've thought that I'm not using the for () {} loop well. Apart from that in the console I get an error https://code.sololearn.com/Wq5He0Hv2ZIW/?ref=app
6 Antworten
+ 3
Of course Kuba, this was only the error elimination. A solution will be e.g. as follows.
Eliminar=(e)=>{
//for(let i=0;i<hija.length;i--){
padre.removeChild(e.target);
//}
}
+ 2
Encontré una forma óptima y sencilla para eliminar los items. Veo que es mejor no darle la funcio al padre sino al elemento li que se crea. Aquí les dejo el código.
https://code.sololearn.com/Wq5He0Hv2ZIW/?ref=app
+ 2
Holger Edud Angulo Castillo for some better handling of entries (some people have big fingers) you could add in the CSS-part following statements:
ul li{
margin-top: 0.8em;
font-size: 1.2em;
}
+ 1
You had written i—, which in this loop makes error. So will it works:
Eliminar=()=>{
for(let i=0;i<hija.length;i++){
padre.removeChild(hija[i]);
}
}
+ 1
Actually, why would you want to use a loop to remove just one element? Wouldn't it remove all the elements *but* the one you clicked, if you correct it as Ja Play suggests?