4
I have a function in my main menu that, when clicked, starts a 'classe'
for the sector in question, everything goes well, however, I need to start the same class again when someone goes back to the sector, and in that, the methods have their duplicate call, follows example:
var Collaborators = function () {
var open_collab_editor = function(){
$(document).on('click', '.edit-collaborator', function (e) {
e.preventDefault();
console.log('fui chamado')
});
}
return {
init: function () {
open_collab_editor();
}
};
}();
$(document).on('click', '.abrir', function (e) {
console.log('inciado');
Collaborators.init();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class='abrir'>Setor x</button>
<button class='edit-collaborator'>Editar (Função iniciada pelo Setor x)</button>
See that every time I click 'Setor x'
it increases the number of times the function 'open_collab_editor()'
is called, this I want to stop and I’m not getting, I need to destroy the first initiation in order to start again, or another way to do this.
I cannot allow the event that is fired on 'open_collab_editor()'
can be fired before clicking 'setor x'
;