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
Post a Comment