JQuery, the live function and different browsers

It’s been a while since I wrote anything here. I’ve been quite busy with lots of different projects. Anyway, one of the latest ones proved to be quite tricky. Here is why.

I am working on an AJAX project and decided to use JQuery to simplify things a bit. JQuery is a great library, so if you haven’t started using it yet, you really should. Anyway, if your web site is to load new elements on the page using AJAX and those newly loaded elements also make some AJAX calls or change the DOM the easiest way to go is to use JQuery’s live function.

I often use the Firebug extension for Firefox to catch errors etc. If you want to debug your code and see, say, values of different variables at different stages in the application you can of course use the JavaScript alert function, especially if you like your screen full of alert windows ;-). The easier way is to use the console.log(some variable); that logs things into Firebug’s console window. Very useful indeed. Or is it?

To make the long story short, undoubtedly it is. The only thing you need to remember is to comment the lines with console.log out or remove them entirely if you want to test the site in any other browser than Firefox (or in Firefox without Firebug extension). If you leave it uncommented your code will most probably not work beyond this point. Easy, obvious? Tell me! I wasted a whole day on trying to figure out what exactly was wrong in my code that it didn’t want to work in Opera, IE, Safari… you name it. For the whole time almost I suspected that only Firefox supports the live function. It took a bit of debugging and simplifying the code to narrow down the problem area.

Anyway, the relief is great and now I can move on with the project :-)