My requirements are the following:
div
, via AJAX.<script>...</script>
)$('document').ready( ... )
partsI've got a javascript function that is called when the AJAX is loaded. I'm trying to "trick it" into executing by doing:
function AjaxLoaded() { $('document').trigger('ready'); }
That doesn't cut it, I'm afraid.
I've seen several responses on Stack Overflow that "evade" this question by changing the code that is returned on the AJAX (make it a function and call it after loading, or just remove the $(document).ready()
). I need to stress out that I can't change the retrieved code on this case.
It would turn into: function OnloadFunction () { alert("test"); } $(document). ready(OnloadFunction); Then you can call OnloadFunction whenever you want to.
$( document ). ready() A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ). ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.
ready() and $(window). load() event is that the code included inside onload function will run once the entire page(images, iframes, stylesheets,etc) are loaded whereas the $(document). ready() event fires before all images,iframes etc. are loaded, but after the whole DOM itself is ready.
jQuery document ready is used to initialize jQuery/JavaScript code after the DOM is ready, and is used most times when working with jQuery. The Javascript/jQuery code inside the $(document). ready() function will load after the DOM is loaded, yet before the page contents load.
Afer some research i created a way to get it to work.
here is my test that shows it working: http://www.antiyes.com/test/test2.php
here is the relevant code:
<script> // easy copy of an array Array.prototype.copy = function() { return [].concat(this); }; // this function is added to jQuery, it allows access to the readylist // it works for jQuery 1.3.2, it might break on future versions $.getReadyList = function() { if(this.readyList != null) this.myreadylist = this.readyList.copy(); return this.myreadylist; }; $(document).ready(function() { alert("blah"); }); </script> <script> // this should be added last so it gets all the ready event $(document).ready(function() { readylist = $.getReadyList(); }); </script>
then in the body I have:
<input type="button" onclick="$(readylist).each(function(){this();});" value="trigger ready" />
basically what i did was add a function to jQuery that copies the readyList before it's cleared out, then it will be available to be used by you.
it looks like the code below doesnt work:
function AjaxLoaded() { $(document).trigger('ready'); }
drop the quotes around document
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With