www.webdeveloper.com
Results 1 to 5 of 5

Thread: JQuery question

  1. #1
    Join Date
    Jan 2007
    Posts
    110

    JQuery question

    Hi I am never that good at JQuery so decided to spend some time to really enhance my skill, I found this really good tut, but there is one thing I don't understand.
    In this http://www.jquery-tutorial.net/intro...e-ready-event/ .ready method, the last example use an overload function,
    puzzeled me:
    <script type="text/javascript">
    $(function()
    {
    $("#divTest3").text("Hello, world!");
    });
    </script>

    the previous two examples both have $(document).ready(....
    the above one doesn't have it.
    What I try to understand is how does JQ know it is $(document).ready? or is it be default the overload has to be $(document).ready?

    Please pardon me for the dumb question, if someone can help me to understand it, I greatly appreciate.

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    It's just a shorter way of specifying a document ready event handler. jQuery simply checks if the argument to $() is a function, and if it is it assumes it's a handler for the document ready event.
    New to web development or in need of a good reference? Check out the Mozilla Developer Network or W3Schools.

  3. #3
    Join Date
    Jan 2007
    Posts
    110
    Thanks for the reply refeezed. So you mean by default JQ will use it in document.ready? Did I understand correctly?
    What if I want to use it in other methods other than .ready()?

  4. #4
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    Quote Originally Posted by MacPC View Post
    So you mean by default JQ will use it in document.ready?
    If the argument is a function, then yeah. If you want to listen for other events than the "ready" event you can use the .on() method. Example:
    Code:
    $("p").on("click", function(){
      alert("Paragraph clicked!");
    });
    Last edited by ReFreezed; 01-11-2013 at 01:46 PM.
    New to web development or in need of a good reference? Check out the Mozilla Developer Network or W3Schools.

  5. #5
    Join Date
    Jan 2007
    Posts
    110
    Oh, thanks a million, now I understand.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles