mardi 20 janvier 2015

Check if an element has event listener on it. no jquery

how to check if an element has event listener on it, if i use an inline function on it like the code below. because i have a function that recalls the function and add the event listener but it cause to have duplication event listener causing it to trigger a function twice. so how can i check it so i can prevent it to add a event listener if is it already exist. thanks! :D



for (var a = 0;a<formFieldInput.length;a++) {
if(formFieldInput[a].hasAttribute("name") && formFieldInput[a].attributes.title.value !== "Valid Until") {
formFieldInput[a].addEventListener("click",function(event) {
toggleFieldList(event,"show");
});
}




Aucun commentaire:

Enregistrer un commentaire