Trigger event by name

Asked

Viewed 27 times

1

i receive by a function the name of the event and the element that should trigger this event ex:

callEvent('click', 'btnEvent')

within this function I would like to return the element and trigger the past event

return :

var elem = document.getElementById('btnEvent');

and then trigger the event but do not know how to trigger the event being that I only have his name in a string would not like to have to do an if for each existing event;

there is something like

elemento.peformEvent('evento');

  • How many different types of events do you have? Triggering events in Javascript is not very simple. Do they have to be DOM events or can they be internal events? Can you explain why you want to defer events in this way?

  • would be gift events, click, keypress, Blur

  • Can you explain why you want to defer to events? Do you want to create events or the code is to run when you trigger these events?

  • I have an element that receives two data-attributes in a date-comes the event it will trigger and in the other date-which element triggers (this in the keypress of this element that contains the data) so it is <input type="text" data-Event="click" dataElement='btnAcionar" id="txtAlgumaCoisa"> so in the keyypress in txtAlgumaTwo js take what element and event is triggered.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.