I have a function that is being called in an event click
and has a parameter defined$container
I'm trying to stop processing that function, open a modal that has a save button, and then continue with the original function by passing the event click
the parameter $container
.
I have the following code but it doesn't work very well for me, I explain it better in the comment of the code.
gm.addEditableAreaClick = function (container) {
$("#myModal").modal();
console.log(container);
//aquí el container cambia cada vez que hago click
$('.save-module').on("click", {param: container}, function(event){
console.log(event.data.param);
//aquí ya no cambia sino que se mantiene el que he clickado la primera vez y lo que me interesa es que cambie.
$(('.' + gm.options.gmToolClass + ':last'), event.data.param)
.before(elem = $('<div>').addClass(gm.options.gmEditRegion + ' ' + gm.options.contentDraggableClass)
.append(gm.options.controlContentElem + '<div class="' + gm.options.gmContentRegion + '">[moz_module]module-id[/moz_module]</div>')).before(cTagClose).prev().before(cTagOpen);
gm.initNewContentElem(elem);
});
};
It happens because a closure is formed , and the value of
container
is enclosed in the function.There are different solutions, the simplest is to remove the existing handler, before setting the new onclick handler.
Then you set it again and it will have the new container assigned.
By declaring container you can use it throughout the scope of the function
It should work, try it