I was about to make delete button for my to-do list code.
this is my code in <script>
var del = $("<ion-icon name='trash'></ion-icon>").click((e)=>{
var p = $(this).parent();
p.remove()
console.log(this)
})
and I got log like this in browser console.
Window {parent: Window, opener: null, top: Window, length: 0, frames: Window, …}
now I found another one is way to use $(e.target)
but I'm still curious why $(this) in callback function is "window".
I'm waiting for your great answer :) thx !
- and this is what I wanna do in my code
$('#task').click((e)=>{
var task = $("<li class='task'></li>").text($('#enter-task').val())
var del = $("<ion-icon name='trash'></ion-icon>").click((e)=>{
var p = $(this).parent();
p.remove()
console.log(this)
})
task.append(del)
$("#tasklist").append(task)
})