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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:00:41+00:00 2026-05-16T22:00:41+00:00

Was recently using some code along the lines of $(#divMenuContainer:visible).hide(explode); However after some time

  • 0

Was recently using some code along the lines of

$("#divMenuContainer:visible").hide("explode");

However after some time spent trying to get it to work I realized my selector was referencing a div that didnt exist.

The result of the query was simply that it didn’t execute.

Obviously this is by design, could anyone explain the logic of why this design choice was made rather than raise some sort of exception?

Not trying to criticise just trying to understand.

  • 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-05-16T22:00:42+00:00Added an answer on May 16, 2026 at 10:00 pm

    There are a few good reasons here, “chainability” is the main drive, the ability to write very terse code by chaining has to throw no errors to work seemlessly, for example:

    $("#divMenuContainer:visible").hide("explode").add("#another").fadeIn();
    

    Each object in the chain, even if it references no DOM elements may have more added later, or let’s take another example:

    $("#divMenuContainer:visible").live("click", function() { ... });
    

    In this case we don’t care about any of the elements the selector found, we care about the selector itself. Here’s another:

    $("#divMenuContainer:visible").find(".child").hide("explode").end().fadeOut();
    

    Even if there are no children, we may want to hop back in the chain afterwards, continuing to use the .prevObject reference to go back up the chain.

    There are dozens of distinct cases like this that show the benefits of the library being the way it is. As for the why, from interviews of John Resig, who is the creator of jQuery, he states that’s just how it worked out. He was after code as terse as he could get it, and the chaining model is what came out of hat, it just happens to have a lot of benefits as well, the example above are just a few of those.

    To be clear, I’m not saying every attribute of chaining is a good one, there are just many upsides to it.


    Let’s take this page as an example, what if we had something like this:

    $(".comment").click(replyToFunction);
    

    Should that fail because there aren’t any comments yet? Well no not really, that’s expected, I wouldn’t want an error here…if the element exists do it, if not don’t. My point is, at least in my experience, not throwing an error because of a missing element is tremendously more useful than throwing one.

    The selector in your question, the #IDselector is a very special case where you expect only a single element, so maybe you could argue it should fail there…but then that wouldn’t be consistent with other selectors, and you want a library to be consistent.

    With pretty much any other selector you expect 0-many elements, so failing when you don’t find any elements would be significantly less desirable in most situations, even more so in the cases like .live() above.

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

Sidebar

Related Questions

I add this problem for quite some time when using NetBeans. Recently I add
I was recently writing some code to do WriteLine using a delegate in .NET
An interesting issue came up recently. We came across some code that is using
I recently began using github and started playing with eclipse's git abilities, using some
I've recently begun working on a project regarding GUI building using some form of
I have recently began using C# to invoke powershell scripts, with some success :)
Recently I was going through a blog and noticed some points about using PDO
Recently I'm working on some air stuff, and I am using Flash Builder and
I'm using MySQL and InnoDB and I've run into some problem recently. This is
I am using cfwheels (coldfusion orm framework). I recently moved some data from my

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.