Sorry for all the info, but the bug submission website isn't working and I really need help on this one!
It seems that when the click handler is being run usually, it's called by 'onclick()'. The time when it is run twice (in Firefox at least) the first time is called by onclick() which is called by handle() - a jQuery function. The second call is as normal. What is this handle() function and why is it explicitly calling my function? --rob > Hmm slightly more info. I spotted the obvious potential stupidity, which was > that I wasn't returning false, so of course it ended my click handler, > spotted the new one and ran that, etc... Adding 'return false;' to the end makes Firefox run test4.1, test4.1, test4.2 then toggle as expected. IE however runs test4.1, then the 2nd iteration it continuously switches between test4.2 and test4.1 without ending the handler chain at all. Removing the 'onclick' attribute and setting the handler with .click() in $(document).ready() fully corrects the fault in firefox, hence this is the same fault I encountered yesterday. In IE it makes no difference and it still bounces between the two click handlers after the first iteration. --rob > Further to my last email regarding unbind("foo") not being able to remove > events set in the HTML "onfoo" attribute, is another problem which is harder > to work around. Using two functions to handle the click event for a button, each function swapping the handler to the other. (Ignore that this can be done with toggle(), this is a simplified test script.) Behaviour is different in Firefox2.0.0.2 and IE6.0. In FF, the test runs as follows for each click: 1. alerts "tested 4.1" as expected 2. alerts "tested 4.1" then alerts "tested 4.2" 3. alerts "tested 4.1" as expected Each click after this runs as expected. In IE6.0, the test runs as follows: 1. alerts "tested 4.1" as expected 2. alerts "tested 4.2" then alerts "tested 4.1" Each click after this runs the same as the 2nd. What's even more odd is that if the final line running .click() in Test4_1() or Test_2() is commented out, everything also behaves as expected. I'll file this as soon as the bug-reporter stops telling me the the database is locked; in the meantime can anyone check to make sure it's not me being stupid, or suggest a workaround? Thanks all! This is the test page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv='content-type' content='text/html; charset=ISO-8859-1' /> <title>Tester</title> <script src='/jquery.js' type='text/javascript'></script> <script type='text/javascript'><!-- function test4_1() { alert('tested 4.1'); $("#testButton4").removeAttr("onclick"); $("#testButton4").unbind("click"); $("#testButton4").html("Test 4.2"); $("#testButton4").click(test4_2); } function test4_2() { alert('tested 4.2'); $("#testButton4").removeAttr("onclick"); $("#testButton4").unbind("click"); $("#testButton4").html("Test 4.1"); $("#testButton4").click(test4_1); } // --></script> </head> <body> <p style='background:red'>Uses removeAttr() and unbind(), then click() to rebind as it toggles between two tests <button id="testButton4" onclick="test4_1()">Test 4.1</button></p> </body> </html> --rob ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ < ---------- Original Message ---------- FROM: Rob Desbois <[EMAIL PROTECTED]> TO: <discuss@jquery.com> DATE: Tue, 13 Mar 2007 14:42:40 +0000 SUBJECT: [jQuery] Bug: event binding / unbinding. help! Further to my last email regarding unbind("foo") not being able to remove events set in the HTML "onfoo" attribute, is another problem which is harder to work around. Using two functions to handle the click event for a button, each function swapping the handler to the other. (Ignore that this can be done with toggle(), this is a simplified test script.) Behaviour is different in Firefox2.0.0.2 and IE6.0. In FF, the test runs as follows for each click: 1. alerts "tested 4.1" as expected 2. alerts "tested 4.1" then alerts "tested 4.2" 3. alerts "tested 4.1" as expected Each click after this runs as expected. In IE6.0, the test runs as follows: 1. alerts "tested 4.1" as expected 2. alerts "tested 4.2" then alerts "tested 4.1" Each click after this runs the same as the 2nd. What's even more odd is that if the final line running .click() in Test4_1() or Test_2() is commented out, everything also behaves as expected. I'll file this as soon as the bug-reporter stops telling me the the database is locked; in the meantime can anyone check to make sure it's not me being stupid, or suggest a workaround? Thanks all! This is the test page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv='content-type' content='text/html; charset=ISO-8859-1' /> <title>Tester</title> <script src='/jquery.js' type='text/javascript'></script> <script type='text/javascript'><!-- function test4_1() { alert('tested 4.1'); $("#testButton4").removeAttr("onclick"); $("#testButton4").unbind("click"); $("#testButton4").html("Test 4.2"); $("#testButton4").click(test4_2); } function test4_2() { alert('tested 4.2'); $("#testButton4").removeAttr("onclick"); $("#testButton4").unbind("click"); $("#testButton4").html("Test 4.1"); $("#testButton4").click(test4_1); } // --></script> </head> <body> <p style='background:red'>Uses removeAttr() and unbind(), then click() to rebind as it toggles between two tests <button id="testButton4" onclick="test4_1()">Test 4.1</button></p> </body> </html> --rob ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ < ---------- Original Message ---------- FROM: Rob Desbois <[EMAIL PROTECTED]> TO: jQuery Discussion. <discuss@jquery.com>, <discuss@jquery.com> DATE: Tue, 13 Mar 2007 15:03:51 +0000 SUBJECT: Re: [jQuery] Bug: event binding / unbinding. help! Hmm slightly more info. I spotted the obvious potential stupidity, which was that I wasn't returning false, so of course it ended my click handler, spotted the new one and ran that, etc... Adding 'return false;' to the end makes Firefox run test4.1, test4.1, test4.2 then toggle as expected. IE however runs test4.1, then the 2nd iteration it continuously switches between test4.2 and test4.1 without ending the handler chain at all. Removing the 'onclick' attribute and setting the handler with .click() in $(document).ready() fully corrects the fault in firefox, hence this is the same fault I encountered yesterday. In IE it makes no difference and it still bounces between the two click handlers after the first iteration. --rob > Further to my last email regarding unbind("foo") not being able to remove > events set in the HTML "onfoo" attribute, is another problem which is harder > to work around. Using two functions to handle the click event for a button, each function swapping the handler to the other. (Ignore that this can be done with toggle(), this is a simplified test script.) Behaviour is different in Firefox2.0.0.2 and IE6.0. In FF, the test runs as follows for each click: 1. alerts "tested 4.1" as expected 2. alerts "tested 4.1" then alerts "tested 4.2" 3. alerts "tested 4.1" as expected Each click after this runs as expected. In IE6.0, the test runs as follows: 1. alerts "tested 4.1" as expected 2. alerts "tested 4.2" then alerts "tested 4.1" Each click after this runs the same as the 2nd. What's even more odd is that if the final line running .click() in Test4_1() or Test_2() is commented out, everything also behaves as expected. I'll file this as soon as the bug-reporter stops telling me the the database is locked; in the meantime can anyone check to make sure it's not me being stupid, or suggest a workaround? Thanks all! This is the test page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv='content-type' content='text/html; charset=ISO-8859-1' /> <title>Tester</title> <script src='/jquery.js' type='text/javascript'></script> <script type='text/javascript'><!-- function test4_1() { alert('tested 4.1'); $("#testButton4").removeAttr("onclick"); $("#testButton4").unbind("click"); $("#testButton4").html("Test 4.2"); $("#testButton4").click(test4_2); } function test4_2() { alert('tested 4.2'); $("#testButton4").removeAttr("onclick"); $("#testButton4").unbind("click"); $("#testButton4").html("Test 4.1"); $("#testButton4").click(test4_1); } // --></script> </head> <body> <p style='background:red'>Uses removeAttr() and unbind(), then click() to rebind as it toggles between two tests <button id="testButton4" onclick="test4_1()">Test 4.1</button></p> </body> </html> --rob ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ < ---------- Original Message ---------- FROM: Rob Desbois <[EMAIL PROTECTED]> TO: <discuss@jquery.com> DATE: Tue, 13 Mar 2007 14:42:40 +0000 SUBJECT: [jQuery] Bug: event binding / unbinding. help! Further to my last email regarding unbind("foo") not being able to remove events set in the HTML "onfoo" attribute, is another problem which is harder to work around. Using two functions to handle the click event for a button, each function swapping the handler to the other. (Ignore that this can be done with toggle(), this is a simplified test script.) Behaviour is different in Firefox2.0.0.2 and IE6.0. In FF, the test runs as follows for each click: 1. alerts "tested 4.1" as expected 2. alerts "tested 4.1" then alerts "tested 4.2" 3. alerts "tested 4.1" as expected Each click after this runs as expected. In IE6.0, the test runs as follows: 1. alerts "tested 4.1" as expected 2. alerts "tested 4.2" then alerts "tested 4.1" Each click after this runs the same as the 2nd. What's even more odd is that if the final line running .click() in Test4_1() or Test_2() is commented out, everything also behaves as expected. I'll file this as soon as the bug-reporter stops telling me the the database is locked; in the meantime can anyone check to make sure it's not me being stupid, or suggest a workaround? Thanks all! This is the test page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv='content-type' content='text/html; charset=ISO-8859-1' /> <title>Tester</title> <script src='/jquery.js' type='text/javascript'></script> <script type='text/javascript'><!-- function test4_1() { alert('tested 4.1'); $("#testButton4").removeAttr("onclick"); $("#testButton4").unbind("click"); $("#testButton4").html("Test 4.2"); $("#testButton4").click(test4_2); } function test4_2() { alert('tested 4.2'); $("#testButton4").removeAttr("onclick"); $("#testButton4").unbind("click"); $("#testButton4").html("Test 4.1"); $("#testButton4").click(test4_1); } // --></script> </head> <body> <p style='background:red'>Uses removeAttr() and unbind(), then click() to rebind as it toggles between two tests <button id="testButton4" onclick="test4_1()">Test 4.1</button></p> </body> </html> --rob ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/