user901886
user901886

Reputation: 353

Is there any way to call function 'before document ready' in Jquery?

I want to call function before document get ready, so is there any method in Jquery to do this?

Upvotes: 35

Views: 97385

Answers (3)

leenbean16
leenbean16

Reputation: 152

If you are using .hide() or display: none; - the hiding of the divs will be displayed.

try:

visibility: hidden;

it worked for me after trying many other ways.

Upvotes: -8

pimvdb
pimvdb

Reputation: 154838

If you simply call a function in the head tag it will execute immediately, before the DOM is even parsed (that's the 'problem' that ready solves).

<!doctype html>
<html>
    <head>
        <script>alert(1)</script>
    </head>
    <body>
    </body>
</html>

Upvotes: 38

Scott
Scott

Reputation: 2793

Just call your function before the document ready statement.

<script>
   thisWillFireImmediately();

   $(function() {
      thisWillFireOnDocumentReady();
   });
</script>

Upvotes: 27

Related Questions