Does something like an onevent
event listener exist?
I would like to do something like this:
window.addEventListener("event", function(event) {
console.log(event.type);
});
Does something like an onevent
event listener exist?
I would like to do something like this:
window.addEventListener("event", function(event) {
console.log(event.type);
});
in the event you want logged you can just add "e" in the fuction and do console.log(e);
for example $('#theEvent').on("blur",function(e){
console.log(e);
});
and if you want to catch a certain event you can do
$('#theEvent').on("blur click",function(e){
if(e.type === "click"){
console.log(e.type + "The user did click");
}else{
console.log(e.type + "The user did blur");
}
});
An other way to do it with case switch
$('#theEvent').on("blur click focus",function(e){
switch(e.type){
case "click":
console.log("The user clicked.");
break;
case "blur":
console.log("The user blurred.");
break;
case "focus":
console.log("The user focused.");
break;
}
});
<!-- html sample -->
<input type='text' id="theEvent"/>
This is a random example but i think you get the idea you can do alot of if statements, so when the right event was triggered it will run the code