2

I have a problem that when I try to delete the li that I made in js, the following code will delete all the list not just the clicked li
and when choosing the parent the span does not work properly

function showdata() {
    var newtodo = $("#newtodo").val();
    $("ol").append('<li class"batodo" >' + newtodo + '<span   class="deltodo">' +" x" + "</span>" + "</li>");
}

$(".deltodo").click(function() {
    $(this).parents(".batodo").remove();
});
Alexandru Severin
  • 6,021
  • 11
  • 48
  • 71

2 Answers2

1

In this case you can use:

$(this).parent().remove();
Serg Chernata
  • 12,280
  • 6
  • 32
  • 50
0

the working code thanks for helping :)

function showdata() {
var newtodo = $("#newtodo").val();
$("ol").append('<li class"batodo" >' + newtodo + '<span class="deltodo">' +" del" + '</span>' + "</li>");
$(".deltodo").click(function(){
        $(this).parents("li:first").remove();
    });

};