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 651597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:10:46+00:00 2026-05-13T22:10:46+00:00

I have a simple JavaScript file that has three jQuery $document.ready functions. All three

  • 0

I have a simple JavaScript file that has three jQuery “$document.ready” functions. All three attach a facebox modal dialog to various links on my page.

This means I’m calling “$document.ready” three times.

First of all, is this advisable? Is it something I should avoid doing?

The app works fine but I’m wondering browsers prefer one “$document.ready” function.

I’m not sure what the best practices are here. Here’s the code (it’s a rails app):

$(document).ready(function() {  
    $('#login-link').facebox({  
        loadingImage : '/images/loading.gif',  
        closeImage   : '/images/closelabel.gif',  
    });  
    $.facebox.settings.opacity = 0.75;
    $(document).bind('reveal.facebox', function() {  
        $('#new_user_session').submit(function() {  
            $.post(this.action, $(this).serialize(), null, "script");  
            return false;  
        });  
    });  
});  


$(document).ready(function() {  
    $('#contact-link').facebox({  
        loadingImage : '/images/loading.gif',  
        closeImage   : '/images/closelabel.gif',  
    });  
    $.facebox.settings.opacity = 0.75;  
    $(document).bind('reveal.facebox', function() {  
        $('#new_contact').submit(function() {  
            $.post(this.action, $(this).serialize(), null, "script");  
            return false;  
        });  
    });  
});  

jQuery(document).ready(function($) {
    $('a[rel*=facebox]').facebox()
})

Now, it would be fairly easy to refactor this code into one “$document.ready” method but I would only do that if it was advisable, cos it’s cleaner the way I’ve got it right now.

  • 1 1 Answer
  • 2 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-05-13T22:10:46+00:00Added an answer on May 13, 2026 at 10:10 pm

    No there is no limit and the only reason you would HAVE to refactor is to control order of execution.

    Browser js engines know nothing of $().ready. This is a jquery function that is designed to provide consistent behavior across platforms.

    You are doing just fine.

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

Sidebar

Related Questions

let's say I have a simple javascript like so: $(document).ready(function(){ if(login == 1) {
I have some simple JQuery / Javascript to perform some simple logic for all
I have added a simple .js file to my page that has some pretty
I have an ASP.NET MVC website which has a particular javascript file that needs
I have a sample.xhtml file which has few lines of javascript. This javascript will
I have a simple JavaScript game that sends a score to PHP by adding
I have a very simple JavaScript/jquery code which won't just work correctly. The problem
We have moved a lot of images and javascript file that was inside class
I have designed a stylesheet/javascript files bundler and minifier that uses a simple cache
I have a simple script that should cause one of three divs to be

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.