How to delete parent element using jQuery

后端 未结 7 1732
深忆病人
深忆病人 2020-11-28 05:01

I have some list item tags in my jsp. Each list item has some elements inside, including a link (\"a\" tag) called delete. All that I want is to delete the entire list item

相关标签:
7条回答
  • 2020-11-28 05:22

    I have stumbled upon this problem for one hour. After an hour, I tried debugging and this helped:

    $('.list').on('click', 'span', (e) => {
      $(e.target).parent().remove();
    });
    

    HTML:

    <ul class="list">
      <li class="task">some text<span>X</span></li>
      <li class="task">some text<span>X</span></li>
      <li class="task">some text<span>X</span></li>
      <li class="task">some text<span>X</span></li>
      <li class="task">some text<span>X</span></li>
    </ul>
    
    0 讨论(0)
提交回复
热议问题