Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    23
    Thanks
    2
    Thanked 0 Times in 0 Posts

    newbie question about jquery

    hey, sorry about the newbie question, but how exactly does one get something to say... fade in when the document is ready?
    what i'm using right now (which isn't working.) is
    Code:
    $(document).ready(function(){
    $('#body').ready(function(){
    $('#body').fadeIn(slow);
    });
    });
    any help would be appreciated!
    thanks!

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,618
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Just put your JavaScript at the bottom of the page (just before </body> ) and then you will not need to test for it as the document is ready at that point.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    23
    Thanks
    2
    Thanked 0 Times in 0 Posts
    so i should fore go the external? i'm experimenting withthe thought of using a .mouseOver, do you think that would be better?

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,629
    Thanks
    6
    Thanked 1,002 Times in 975 Posts
    The “anonymous” dollar function is a shortcut for $(document).ready(), I don’t understand why people still write it the long way.
    Code:
    <head>
    …
    …
    <style type="text/css">
    #example {display: none;}
    </style>
    <script type="text/javascript">
    $(function() { // this is only executed when the document is ready
       $('#example').fadeIn('slow');
    });
    </script>
    </head>
    <body>
    …
    …
    <div id="example"></div>
    …
    </body>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •