On a particular page, I use json to load a bit of html code that displays information about what the user submitted when he clicks on something.
In this case, the user is picking his favorite baseball player and the json returns some html code that formats and displays the name of the player.
When that html is loaded on the page, the live click javascript function no longer applies to the html that is loaded. Is there some way I can refresh the javascript so that it applies to it?
After doing a lot of research and talking to several people, I found that I need to re-bind the event after the json callback.
This was a great help:
http://jetlogs.org/2009/01/29/re-binding-jquery-events-on-ajax-callbacks/
When using jQuery’s .click() method and rendering new html, the javascript that was originally attached to it, needed to be attached again.
This is more easily solved by using the .live() method with the ‘click’ option. The .live() method automatically re-binds the new code.