1
Is there any way to disable and activate an existing event in an object?
Example, I have an event in an element <img onclick="foo();">
On this same page, there is an action where, while running, you need to prevent the user from performing events from other objects.
For this, when running such event, all others are disabled.
The problem is that I can’t find anything in the Jquery documentation regarding this.
The only way is to delete the event from the other objects and when you need to activate them again you need to re-create these events.
That way it works well, however, I think there could be something more economical like a simple "enable", "disable".
I am using Jquery, however, if there is a way to solve directly by Javascript, it is obviously quite valid.
I thought that disabling the object would work, but it does not work. Even with the object set to "disabled", events persist normally.
Example:
<img id="bar" onclick="foo();">
/*
Tentei com attr() e prop(). Ambos não surtem efeito.
*/
//$('#bar').prop('disabled',true);
$('#bar').attr('disabled',true);
When you click on the object, it still triggers the event, even if it is disabled.
Is this due to the object type or some header? In HTML I am using Strict DTD.
Another way to solve would be to open a modal in front of the entire screen, preventing access to the bottom layer, but I want to avoid this for now.
Daniel, you managed to solve this problem?
– Sergio
Sorry Sergio, I forgot to mark the answer. I was in the room with yours and Sneeps Ninja’s answer. In the end I did as Ninja suggested, but I liked more than you posted so I will mark yours as accepted. I will use this technique in a next system upgrade.
– Daniel Omine