I am trying to create a function that will delete the parent of the parent node of a button element when it is clicked. The code I have written so far does not seem to be working and no errors are being thrown. Can anyone help me figure out how to achieve this?
Here is an example of the script I am using:
data () {
return {
items: []
}
},
methods: {
deleteItem(event){
let con = confirm('Are you sure?');
if(con) {
let par = event.target.parentNode.parentNode;
for( let i = 0; i < par.length; i++) {
if(event) {
this.items.items.splice(i, 1);
}
}
}
},
}
Here is an example of the table structure:
<table>
<thead>
<tr>
<th>Item</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr v-for="item in items">
<td><input type="text" v-model="item.q" required></td>
<td><button v-on:click.prevent="deleteItem">X</button></td>
</tr>
</tbody>
</table>
Any help would be greatly appreciated,
-S