jquery - Loading dynamic content into a DIV via Ajax -


i have div getting content on success of ajax data load call:

  $.ajax({     type: 'post',     url: '/load.php',     success: function(msg) {              document.getelementbyid('div').innerhtml = msg;     ... 

within newly loaded content, there objects. therefore, cannot instantiate objects when page loads, since don't yet exist. therefore, instantiate them on ajax success:

  $.ajax({     type: 'post',     url: '/load.php',     success: function(msg) {              document.getelementbyid('div').innerhtml = msg;             $("#button").button();             $("#dp").datepicker();             etc.     } 

this works fine. however, i'm wondering if practice. first of all, every time user triggers function load div, assume of content needs added on , on again browser's object model. well, of jquery instantiation calls need run on , on again.

can let me know if best practice, , if there better way of loading content div?

thanks.

this way know of instantiate widgets on dynamically-added elements, unless particular widget library provides better. event handlers can bound earlier using delegation .on(), widgets require access element @ instantiation time (they modify dom part of initialization).


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -