Simple question (I hope).
I have a page that contains links that when clicked loads up new content into a specified div.
The content that gets loaded (a partial view) contains further links that fire JavaScript code (jQuery).
I have been hooking these links up using jQuery’s live system. It has been recommended to me that I wire-up the buttons in the partial views by placing JavaScript directly into these views or by adding onclick handlers directly to the links (rather than wiring them up with jQuery).
Is there a ‘best practice’ to hooking up dynamic content?
I would argue against in-line JavaScript, be it in a script tag or in onclick handlers. Separation from your presentation logic is always recommended.
As for what to do in that instance, I’d say your best bet would be to use live events or to make use of a callback to assign additional functionality. REF: http://api.jquery.com/jQuery.ajax/