JSFiddle - React, Tailwind, and code Playground
HTML
<div id="ctnr"></div>
CSS
#ctnr {
background: #EEE;
padding: 10px;
}
#ctnr div {
background: #CCC;
border: 1px solid #BBB;
padding: 2px;
margin: 4px;
}
JavaScript
var ctnr = document.getElementById('ctnr');
function removeDiv (d) {
alert('testing');
d.removeEventListener('click', d.custom_Listener , false);
}
function addDiv () {
var div = document.createElement('div');
div.innerHTML = 'test';
div.custom_Listener = function(){removeDiv(this)};
ctnr.appendChild(div);
div.addEventListener('click', div.custom_Listener , false);
}
addDiv();
addDiv();
addDiv();