Question

I'm trying to find a better solution for this problem. I have a game that I'm developing in PHP and it has many different content pages. These content pages contain everything inside the document body. I'm using jQuery click events to call my AJAX which loads an external PHP and updates the game. However, on many pages I have different elements that I'm calling with my jQuery selector. I would like to have just one javascript file to manage all the jQuery events, but according the comment posted on the jQuery site;

*"Note for IE. If you try to assign a live event handler on an element that doesn't exist, then any other live event handlers will not work, you will receive no errors, either."
http://api.jquery.com/live/

Unfortunately, a large portion of my player-base us still using IE 6-8. Because of this, in my footer file, I'm calling many different JavaScript files. I was hoping that someone could tell me a better work around for this, since my game has many different pages, and I don't want to be calling a lot of JavaScript files in my footer.

Alternatively, if there was someway that I could include a javascript file from within the < body > tags, that would be another solution (but I from what I've researched I don't think this is possible).

Thanks.

Was it helpful?

Solution

Try using delegate() instead of live()

delegate is similar to live but instead of propogating the event back to the document.root you can specify the root element in which the event will be handled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top