Are you loading in your function via AJAX? Does it get loaded multiple
times?

If so you might need to do something like this (untested):

var prevMyFunc;
var myFunc;

// ajax returns "myFunc = function(){ ... }"

$('#mainWindow').unclick(prevMyFunc).click(myFunc);
prevMyFunc = myFunc;

Cheers,
-js


On 12/14/06, floepi <[EMAIL PROTECTED]> wrote:



Ahhhh

Please try for yourselves on any page.

var hello = function() {
    alert('funzt nicht');
};
$('#mainWindow').unclick(hello).click(hello);
$('#mainWindow').unclick(hello).click(hello);

If i understand correctly we should only get one alert popping up since we
registered the function globally and unclicked it. But it doesn't work :((

Well i hope we can solve this mystery - thanks very much for your time
guys.

Cheers

Phil



floepi wrote:
>
> I guess i am doing something wrong. If i try this
>
> $('#mainWindow').click(function() { alert("Hello"); });
> $("#mainWindow").unbind( "click", function() { alert("Hello"); });
>
> where the functions are identical, it still does not work. It will
invoke
> the alert function when i click in the mainWindow.
>
> I must be missing something.
>
> Cheers
>
> Phil
>
>
>
> Sam Collett wrote:
>>
>> On 14/12/06, floepi <[EMAIL PROTECTED]> wrote:
>>>
>>> Hi,
>>>
>>> i have the following problem using the events in jQuery:
>>>
>>> $('#mainWindow').click(function(){
>>>  alert('test');
>>> });
>>>
>>> and load this function at the end of a php script:
>>> <?php
>>> bla bla bla
>>> ?>
>>> <script>
>>> my function
>>> </script>
>>>
>>> The problem is that i load this data into the mainWindow which means,
>>> that
>>> the event gets attached each time i load content into the mainWindow.
So
>>> when i click in the mainWindow i get multiple alert messages.
>>>
>>> Is there a way to tell jQuery to overwrite the event if the function
is
>>> the
>>> same. Otherwise i have to use the specific unbind each time i load
data
>>> into
>>> the window, which feels hacky and unnecessary.
>>>
>>> Thanks for your time. Maybe you know how to solve my problem.
>>>
>>> Cheers
>>>
>>> Phil
>>
>> Have you tried 'unclick'?
>>
>> $('#mainWindow').unclick().click(...
>>
>> _______________________________________________
>> jQuery mailing list
>> [email protected]
>> http://jquery.com/discuss/
>>
>>
>
>

--
View this message in context:
http://www.nabble.com/Duplicate-Events-tf2820382.html#a7873813
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to