How to hide the parents of several elements with the same class?

Viewed 52

I am trying to use .hide() from jQuery to hide some the parents of the li's that has the same class. No success so far. I see the other things like .addClass works fine, but .hide() is not working on this one? Can someone give me a hand?

This is my code:

add()

function add() {
  var element = document.getElementById("tasks");
  var name = "acb"
  $(element).append(

    '<div class="d-flex mt-4">' +

    '<span class="col-1">' +
    '<li class="not-done" onclick="done(this)">' + name + '</li>' +
    '</span>' +

    '<span class="col-3">' +
    '<button type="button" class="btn-edit">Edit</button>' +
    '</span>' +

    '</div>'
  )

}

$("#show-done").click(function() {

  $("li.not-done").parent().parent().hide();

  // $("li.done").show();

})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="tasks">
  <div class="d-flex mt-4">

    <span class="col-1">
      <li class="done" onclick="done(this)">xys</li>
    </span>

    <span class="col-3">
      <button type="button" class="btn-edit">Edit</button>
    </span>

  </div>
</div>
<button id="show-done">show</button>

0 Answers
Related