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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:12:43+00:00 2026-06-17T13:12:43+00:00

Is there a (maybe undocumented) placeholder like $.noop for the use in jQuery concatenations?

  • 0

Is there a (maybe undocumented) placeholder like $.noop for the use in jQuery concatenations?

To use in something like the following:

$('selector')[true ? 'method' : '<function that does nothing>']().doSomething();

I’ve tried a lot and ended up with this:

$.fn.noop = function(){ return this; };

But maybe there’s already such a function in the jQuery core?

  • 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-17T13:12:45+00:00Added an answer on June 17, 2026 at 1:12 pm

    Option one:

    Use $.fn.splice. It’s there and it’s always present, but it’s also undocumented (so it may not be present in the future), unreadable, and requires there be no arguments.

    Option two:

    $.fn.noop = function(){return this}. Reliable, readable, predictable, fast. About the only reason to prefer #1 is development time.

    Option three (preferred): Use a plugin for conditionals, which are about the only reason to desire a chainable no-op, such as the Iff plugin by Ben Alman (or write your own).

    Pro: turns

     ... [condition?'method':'noop']() ...
    

    into:

     ... .iff(condition).method().end() ...
    

    That is, it’s more readable than #2, AND you’re not restricted to one call. You can even traverse within iff or nest your conditionals as long as you properly unwind the stack.

    Cons: it’s a plugin, and you’ll need to fetch it; it requires the methods you call are no-ops when operating on the empty collection. All standard jQuery functions (except add) are.

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

Sidebar

Related Questions

Maybe there's no way to solve this the way I'd like it but I
Is there a function which would return true of false based on if the
Is there a way (maybe undocumented?) of importing/exporting color themes for the MATLAB editor?
I would like to know if there is maybe a finally that i can
There maybe some simlar questions to this but I can't see anything that really
Maybe there is no difference, but is either way better than the other (or
Maybe there is a proper term for this, but what if you want to
Is there such a thing? Maybe there should be, I don't think Microsoft built
I'm not very good at regex but maybe there's a simple way to achieve
Is there a working JPA 2 implementation for JBoss server? Or maybe there is

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.