determine from function when an event stops with javascript -
simplified scenario:
- i have click event on button
- inside event call function x
- function x returns value
- click event changes dom using received data (actually renders jquery template)
sample code:
$("button").click(function() { var response = functionx(); dotemplaterendering(response); //(*) }); function functionx() { //some code return some_value; //the click event has finished, make little adjust generated dom (*) }
the questions are:
- do have way determine when click stops form
functionx()
? - or there way
dotemplaterendering()
triggers can capturefunctionx()
doesn't matter if return value, because @ point i'm going able execute code need
the reason behind this part of framework , can't change click event.
you can't return value function , further processing within same function. can schedule code run later using settimeout()
:
function functionx() { //some code settimeout(function() { //the click event has finished, make little adjust generated dom (*) }, 5); return some_value; }
js single-threaded (if ignore web-workers), function pass timeout won't executed until after click event finishes.
alternatively, can bind second click handler same button , processing there - jquery guarantees event handlers (for same event , element) run in order they're bound.
Comments
Post a Comment