+ 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?
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.
-->
+ 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.
-->
+ 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
+ 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
+ 2
Should work as long as you include the remove button in each li
+ 2
thank you everybody 😊😊😊
+ 1
it is not working 😔
+ 1
Legaciy I made with yours :)