I have the following script:
$('#target').bind('click',
function () {
$('#target').css({ 'display': 'none' });
$('#targetFake').css({ 'display': 'inline-block' });
},
function () {
alert('bind callback');
});
The ‘bind callback’ alert seems to be triggering everytime that the ‘#target’ element is being clicked instead of only once when the element is being bound. Can I make a callback to verify that the binding is happening once?
That’s how it should be working: one trigger per click event. The binding happens once per
bindcall; if you accidentally callbindmultiple times with the same handler you will see the handler triggered multiple times by just oneclick.However: what are the two functions doing in your
bindcall? There is no overload that accepts two functions.Other alternatives you might be looking for are:
onefor this purpose.$(...).bind('click', ...).trigger('click').