Monday 15 September 2014

jquery - Calling Function from inside of dynamic loaded .js file not working properly -



jquery - Calling Function from inside of dynamic loaded .js file not working properly -

i'm loading .js & .css file dynamically when known class exist in document. when phone call function within loaded .js immediately, it's not work. if set alert before calling, it's work perfect. why?

if ($(".pdp").length) { sysloadscript("/sysdb/resource/mydatepicker.css"); sysloadscript("/sysdb/resource/mydatepicker.js"); $(".pdp").each(function() { ths=$(this); /* alert("this work alert not without it"); */ ths.mydatepicker({defval:ths.attr("value"),fntsz:12}); }); }

i don't know sysloadscript function does, how it's done regular jquery:

$.getscript('/sysdb/resource/mydatepicker.js', function() { $('.pdp').each(function() { var ths = $(this); ths.mydatepicker({ defval: ths.attr('value'), fntsz: 12 }); }); });

the sec argument $.getscript() callback function, run after script loaded.

jquery function

No comments:

Post a Comment