+ 4

Help me on JavaScript please

My cod-> <ol> <li> a <button onClick="remove">×</button></li> <li> b <button onClick="remove">×</button></li> <li> c <button onClick="remove">×</button></li> </ol> How can I remove which I clicked li?

3rd Jun 2017, 8:49 PM
Serhat Merak
Serhat Merak - avatar
8 Réponses
+ 16
<ol> <li> a <button>×</button> </li> <li> b <button>×</button> </li> <li> c <button>×</button> </li> </ol> <script> onload = function() { var buttons = []; for (var i = 0; i < 3; i++){ buttons[i] = document.getElementsByTagName("button")[i]; } for (var i = 0; i < 3; i++){ buttons[i].onclick=function(){ this.parentElement.innerHTML="" } }} </script> <!-- My bad, maybe i don't understand what you want to do, with this snippet the clicked element and the text inside it will be hidden, or more specifically, will disappear. -->
3rd Jun 2017, 9:38 PM
Maz
Maz - avatar
+ 13
<ol> <li> a <button onClick="remove()">×</button></li> <li> b <button onClick="remove()">×</button></li> <li> c <button onClick="remove()">×</button></li> </ol> <script> onload=function() { function remove(){ this.outerHTML = ""; delete this; } } </script> <!-- Easiest way, Cross-Browser... but not the best. -->
3rd Jun 2017, 9:09 PM
Maz
Maz - avatar
+ 11
Here's my version of answer [Pure JS] https://code.sololearn.com/WPwu9pBdSSGl/?ref=app [JQuery] https://code.sololearn.com/WS74qQn5vLW9/?ref=app If it isnt work please know me. I'll make you another answer
4th Jun 2017, 2:13 AM
김정제(Legacy)
김정제(Legacy) - avatar
+ 6
https://code.sololearn.com/WljvVDpQYIim/?ref=app Check this out. Shud do the trick. Changed Maz's code a bit, his would remove the html from the list item. Mine removes the actual list item element, allowing the items to move up the list. Hope it helps you understand, or at least work on ur project
3rd Jun 2017, 10:22 PM
Russel Reeder
Russel Reeder - avatar
+ 2
Should work as long as you include the remove button in each li
4th Jun 2017, 10:36 AM
Russel Reeder
Russel Reeder - avatar
+ 2
thank you everybody 😊😊😊
4th Jun 2017, 10:40 AM
Serhat Merak
Serhat Merak - avatar
+ 1
it is not working 😔
3rd Jun 2017, 9:15 PM
Serhat Merak
Serhat Merak - avatar
+ 1
Legaciy I made with yours :)
4th Jun 2017, 10:34 AM
Serhat Merak
Serhat Merak - avatar