35

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

user901886
  • 353
  • 1
  • 3
  • 5
  • AFAIK no, but there may be ways to simulate it by placing the script at the right location. What are you trying to do, what is your end goal? – Pekka Aug 25 '11 at 08:03
  • 1
    Call the function outside of document ready! – Shef Aug 25 '11 at 08:03
  • possible duplicate of [Running a function just before $(document).ready() triggers](http://stackoverflow.com/questions/4098504/running-a-function-just-before-document-ready-triggers) – Haim Evgi Aug 25 '11 at 08:03
  • 1
    Call ur function anywhere in dom, it will be called before dom is created. – hungryMind Aug 25 '11 at 08:04

3 Answers3

38

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>
Mike
  • 1,158
  • 5
  • 22
  • 32
pimvdb
  • 151,816
  • 78
  • 307
  • 352
27

Just call your function before the document ready statement.

<script>
   thisWillFireImmediately();

   $(function() {
      thisWillFireOnDocumentReady();
   });
</script>
Scott
  • 2,753
  • 1
  • 24
  • 31
-7

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.

leenbean16
  • 134
  • 12