views:

115

answers:

3

Hi,

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?

A: 

Both solutions are ok, but I consider messy adding javascript calls in my partials... so I'd use live

marcgg
A: 

no - ideally you should not use inline event handlers. Ideally you should assign events using js or if its a link use an anchor tag

matpol
+2  A: 

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/

BBonifield