Click event multiplying

1

I have a directory listing system that displays files and folders, when I click on an item, it displays a (single) menu that is already set on the page and can be used by all files. In this menu, there is an option called DELETE, the problem is there. To open the menu you have to click, however, I need to know the id of the file chosen to use in the deleteFile function:

var files = document.getElementsByClassName("backgroundFiles");
for(i=0;i<files.length;i++){
    files[i].addEventListener("click", function(event){
        menuFiles(this.id, event.clientX, event.clientY);
        deleteFile(this.id);
    });
}

In the deleteFile function there is another click event that will be triggered when the user clicks on the DELETE menu option:

function deleteFile(idElement){
    document.getElementById("a_dele").addEventListener("click", function(event){
        var chave = prompt("Digite a chave de segurança");
        ...
    });
}

The problem is that these events are multiplying, when giving the first click everything is ok, already in the second, the prompt appears twice, the third click appears three times the prompt and so on. Could someone help me with a solution?

    
asked by anonymous 07.07.2018 / 19:05

0 answers