0
I need to check if in a View there is an Onclick event that executes the test function
if($.minhaview.propriedade == 'teste'){
alert("existe um evento onClick com o valor teste");
}
0
I need to check if in a View there is an Onclick event that executes the test function
if($.minhaview.propriedade == 'teste'){
alert("existe um evento onClick com o valor teste");
}
0
If you just want to test if the variable already has the value of an assigned function, you can use the typeof function.
if(typeof $.minhaview.propriedade === 'function')
{
// ...
}
0
If you added an element to a property onclick
, can test it, for example:
if ($.minhaview.onclick) {
// faça algo...
}
But if you added the event with addEventListener('click', evento)
ai the answer is: it is not possible to verify if there is an event in this element.
The Observer that manages element events in javascript only allows you to add and remove events, but does not expose the event list.
However, it is possible to modify this behavior by modifying the event prototype, just as jQuery does.
You could create a way to store in some object property the list of events contained in it. But by default the W3C specification does not foresee such exposure.
Browser other questions tagged javascript events
You are not signed in. Login or sign up in order to post.
Can you give a little more context? What is
propriedade
? And where the functionteste
is defined? It is in scope when thisif
wheel?– bfavaretto