why would $('#foo') fail?
I have a webapp that uses JQuery (version 1.2) for doing javascript DOM manipulation. The webapp works great most of the time. However, we have an easily reproducible bug. 99% of the time, a particular call to JQuery's $('#foo') function works perfectly. But under one particular code path, it is unable to find the DOM object, even though the DOM object does seem to be there when looking at the page using "view source".
The bug happens on IE6, IE7 and Firefox. (But, the bug goes away on Firefox if I'm debugging with Firebug.) The bug happened with both JQuery 1.1.4 and JQuery 1.2.
Can anyone tell me why $('#foo') would ever fail to find a DOM object? In a different forum, someone suggested that it might be related to an ajax call that is updating the page with text instead of DOM objects. It's not clear to me if that's related to this bug or not. My app does have an ajax call that uses $('#someDiv').append(someHtml) to append html to a div, but that div isn't very close to the failing $('#foo'). Is $('#someDiv').append(someHtml) the right way to add DOM nodes to the page?
If you are willing to look deeper...
Currently, the webapp is in private beta, so it's not accessible to the public. However, if you are a JQuery expert and are willing to take a look at the problem, send me a message and I will give you a login to the site.
Also, I have created a dummy version of the app that includes the UI and a dummy back-end. If it would be helpful, I would be happy to send you the source of the dummy version. The app is a java app that runs under Tomcat or any other J2EE container.