0

If I use $(document).ready() multiple times then what will be the execution order. Which code is executed first.

Vaibhav D
  • 605
  • 9
  • 12
  • 2
    it is executed in the order in which they are added – Arun P Johny May 02 '14 at 06:36
  • document.ready() callbacks are called in the order they were registered. If you register your testing callback first, it will be called first. http://stackoverflow.com/questions/10883786/jquery-enforce-order-of-execution-of-document-ready-calls – Neel May 02 '14 at 06:38
  • Question is good but duplicate. – Satpal May 02 '14 at 06:38
  • All will get executed and On first Called first run basis!! http://stackoverflow.com/questions/5263385/jquery-multiple-document-ready – Ankur Aggarwal May 02 '14 at 06:38

1 Answers1

2

Code gets executed from the top to the bottom.

HTML

<div id="document-ready"></div>

jQuery

$(document).ready(function() {
    $("#document-ready").append("Document ready 1<br>");
});

$(document).ready(function() {
    $("#document-ready").append("Document ready 2<br>");
});

$(document).ready(function() {
    $("#document-ready").append("Document ready 3<br>");
});

Output

Output (image)

JSFiddle demo

Explanation

You see that it first outputs 'Document ready 1', which means that that one got executed first.

Daan
  • 2,680
  • 20
  • 39