Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

second $(document).ready event jQuery

I'm using some external jQuery with $(document).ready() to insert adverts after the document ready event has fired, something like:

$(document).ready( function() {
  $('#leaderboard').html("<strong>ad code</strong>");     
});

This is to prevent the UI being blocked by the slow loading of the adverts. So far it's been working well.

Now I need to insert some more ads though our CMS system, this can't be part of the external JS file, so I'm wondering can I use a second document ready event and insert it using an inline script tag? If so, what will be the order of execution the external JS document ready event first or the inline script?

like image 338
Tom Avatar asked Apr 17 '09 10:04

Tom


1 Answers

You can use as many event methods as you want, jquery joins them in a queue. Order of method call is same as definition order - last added is last called.

A useful thing may be also that, you can load html code with script using ajax and when code is loaded into DOM $().ready() also will be called, so you can load ads dynamically.

like image 200
Thinker Avatar answered Sep 19 '22 17:09

Thinker