I have a function in my main menu that, when clicked, starts a 'classe'
for the sector in question, everything happens well, however, I need to start the same class again when someone returns to the sector, and in that, the methods have their duplicate call, follow 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 on 'Setor x'
it increases the number of times the 'open_collab_editor()'
function is called, which I want to prevent and I'm not getting it, I need to destroy the first initiation in order to start again, or another way to do this.
I can not allow the event that fires at 'open_collab_editor()'
to be triggered before clicking 'setor x'
;