I have a focusout event
$('.alpha').on("focusout", function () {...});
and I want want to trigger it from somewhere else in the code.
I tried $('#input12').focus().blur();
and also tried $('#input12').trigger("focusout")
edit: I am using a dynamically generated elements.
but no luck there...
the element #input12 has the class name alpha so I expect The focusout event to be triggered.
Is there any way of getting it done?
here is a jsfiddle example of when I am trying to do https://jsfiddle.net/jnmnk68d/
You need to delegate your events to a non-dynamic parent element.
In this example, we listen for
focusoutevents on theformbut only fire our function if the event's target matches the selector (in this case".alpha"). This way the event can be fired on any elements that match now or in the future.Here's a full demo which allows you to see how using delegated events we are able to trigger the event on dynamically inserted content.