Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7969555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:15:16+00:00 2026-06-04T07:15:16+00:00

I use document ready all the time, but I’m watching some tutorial videos to

  • 0

I use document ready all the time, but I’m watching some tutorial videos to really KNOW whats going on instead of just knowing from typing it so much.

I had always put it in an anonymous function out of habit as thats how its always done, but now I see if its NOT in an anonymous function (say alert(); for instance), it will execute NOT when the DOM is loaded but immediately when that javascript loads. It must be in an anonymous function for this to happen how its supposed to (when the whole page loads) and the event listeneter triggers that its ‘ready’.

Why is this?

furthermore I often see something like function(i){}(i), what does this mean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:15:17+00:00Added an answer on June 4, 2026 at 7:15 am

    In this answer, I’m going to use the shorthand for $(document).ready(...), which is $(...), provided that a function is passed.

    The function doesn’t have to be anonymous; you can write this for example:

    function doStuff() {
    }
    
    $(doStuff);
    

    I think what you mean is if you try this:

    $(alert('Yo!'));
    

    It will indeed alert right away. This is because a function is expected, and alert() is a function call. This, on the other hand, would work (albeit strangely):

    $(alert);
    

    For your second question, what function(i){}(i) does is declare a function object with one parameter, then immediately run it with a provided argument. This is a useful way to use an object without needing it to be global and without it needing to have a certain name. For example, this:

    (function($) {
        // Do stuff with $
    })(jQuery);
    

    Lets you alias jQuery as $.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this script: $(document).ready(function() { $page = jQuery.url.attr(file); alert(page); }); but I get
I generally use this in jquery $(document).ready(function() { //stuff } I was just on
I use tag-it plugin from https://github.com/aehlke/tag-it/downloads . How to disable adding new tags? $(document).ready(function
When should you use document.all vs. document.getElementById ?
this is my first time trying to use document classes in AS3 and im
The logged value is shown below: but why when I use document.write or alert
first of all, thanks for your time. I'm trying to use jqGrid to make
This has been bugging me for quite some time now. All I want to
Possible Duplicate: Why use document.write? Considering the negative effects of document.write(), why are most
Can someone explain to me why I cannot use document.getElementById('id').value inside of a function?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.