javascript - createElement ile bir HTML elementi oluştururken addEventListener neden çalışmıyor?


Yani kodumda basit bir div oluşturup bir olay dinleyicisi ekliyorum

const new_card = document.createElement('div');
new_card.className = 'card';
new_card.style.left = e.pageX + "px"
new_card.style.top = e.pageY + "px"
new_card.addEventListener('onclick', handler);

İşleyici için kod:

const handler = (event) => {
    if ((event.target as HTMLElement).parentElement!.className == 'card') {
        get_selected_card((event.target as HTMLElement));
    }
};

ve sonra işlemci bu fonksiyonu çağırır:

function get_selected_card(elmnt: HTMLElement | null) {
    console.log(elmnt);
};

ama kod çalışmıyor, konsolumda hiçbir yanıt almadım