javascript - Referencing Ajax-Loaded Element in JS Object Instance -


how reference element doesn't exist yet within javascript object instance?

var dynamic = function(el) {    this.$instance = $(el); }  var dynamicinstance = new dynamic('#dynamic'); 

since #dynamic element loaded via ajax, script doesn't see when dynamicinstance created , can't reference it.

if helps solve issue, reference element inside object without passing in when it's created -- still unclear on how make object aware of element.

if want keep things decoupled can accept callback function parameter , call once new element loaded , appended dom

function doajaxcall(callback) {     $.ajax({          success : function(response) {               //logic create new element based on response               callback();          }       }); }  doajaxcall(function() {     var dynamic = new dynamic('#dynamic'); }); 

in way keep decoupled while avoiding race condition created ajax calls.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -