I have the following chunk of code
$(function(){
var TaskEvent = new CustomEvent('TaskAdded',{
detail: {
message:'A task fue ponida, champion'
},
bubbles:true,
cancelable:true
});
var btn = $("#boton");
function HandleSugar(e){
console.log(e.detail.message);
}
btn.click(function(e){
document.dispatchEvent(TaskEvent);
});
$(document).on('TaskEvent',HandleSugar);
})
When clicking in the button (#boton) nothing happens. Any idea?
Some clarifications:
You are listening for TaskEvent
but the event is actually TaskAdded
.
$(document).on('TaskEvent',HandleSugar);
should be
$(document).on('TaskAdded', HandleSugar);