jquery unbind function event once executed -
hi folks, please me fix : suppose call same javascript function anchors different parameter
<a id="edit1" onclick="foo(1)"></a> <a id="edit2" onclick="foo(2)"></a> function foo(id) { // let's code here hide clicked anchor , show new anchor cancel-edit id }
the scenario :
- i clicked in first anchor - first anchor replaced new anchor :
- how can disable function, when click in second anchor nothng.
- now suppose clicked in anchor id cancel-edit pull anchor id edit1 , reactivate foo function when reclick in second anchor execute again foo function...
i hope it's clear :x ! in advance.
if want disable elements after 1 clicked, set flag:
var enabled = true; function foo(id) { if( enabled ) { // run code enabled = false; } }
it continue run, code in if
statement not after first click.
function stop() { // replace original anchor enabled = true; // enable "foo" handler }
when new anchor stop()
clicked, replace original anchor, , set enabled
true
foo()
work again.
Comments
Post a Comment