I have a list, and there is a delete button in each list group item. The delete button should be used to remove the list item. I can just delete the button right now, but I'd like to remove the entire li part.
function remove(ev) {
var elem = document.getElementById(ev.target.id);
elem.this.parentNode.id.remove();
console.log(elem.this.parentNode.id);
}
<ul class="list-group">
<li class="list-group-item">
<p>Item 1</p>
<button type="button" id="btn1" onclick="remove(event)" class="Button">Click</button>
</li>
<li class="list-group-item">
<p>Item 1</p>
<button type="button" id="btn1" onclick="remove(event)" class="Button">Click</button>
</li>
</ul>
Solved! Go to Solution.
Maybe try this instead:
function remove(ev) {
var listItem = ev.target.parentNode;
listItem.parentNode.removeChild(listItem);
}
Maybe try this instead:
function remove(ev) {
var listItem = ev.target.parentNode;
listItem.parentNode.removeChild(listItem);
}
Thanks