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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:53:23+00:00 2026-05-25T20:53:23+00:00

I saw this code and I’m not clear what the ‘ ! ‘ does

  • 0

I saw this code and I’m not clear what the ‘!‘ does in this line of jQuery code on the return on the jQuery object:

$('#remove').click(function() {
    return !$('#select2 option:selected').appendTo('#select1');
});

EDIT

What is a good case to do this?

  • 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-25T20:53:23+00:00Added an answer on May 25, 2026 at 8:53 pm

    It converts the result of $('#select2 option:selected').appendTo('#select1') to a boolean, and negates it.

    However, as the result of appendTo is always a jQuery object, and an object (jQuery or not) is always truthy, the result of !$('#select2 option:selected').appendTo('#select1') is always false.

    So what we have is effectively:

    $('#remove').click(function() {
        $('#select2 option:selected').appendTo('#select1');
    
        return false;
    });
    

    Returning false in a jQuery event handler will stop the default event action occuring (e.g. the submission of a form/ navigation of a hyperlink) and stop the event propagating any further up the DOM tree.

    So what we have is effectively:

    $('#remove').click(function(e) {
        $('#select2 option:selected').appendTo('#select1');
    
        e.preventDefault();
        e.stopPropagation();
    });
    

    Using return false instead of e.preventDefault(); e.stopPropagation(); is OK, but using the return !$(..) as a shortcut for the first example is ridiculous, and there is no need to do it.

    Just to reiterate my point, the most important thing to note here is that there is never, ever a good reason/ case to do this.

    Links:

    1. Docs for bind() (alias for click())
    2. Docs for preventDefault()
    3. Docs for stopPropagation()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw this code but I couldn't understand what it does: inline S* O::operator->()
I recently saw this code on another post ( jQuery Set Cursor Position in
I saw this code line in the Direct3D SDK and I want to know
I saw this code in another SO post: jQuery UI Autocomplete with ASP MVC
I saw this code in Erlang: [X-$0 || X<-someFun()] In that line I found
I was reading subr.el and saw this code: (defalias 'backward-delete-char 'delete-backward-char) (defalias 'search-forward-regexp (symbol-function
I once saw this line of code: std::cout %lt;%lt; Hello world! %lt;%lt; std:: endl;
I saw this code snippet during our lab and it actually compiles in MSVC2008
I just saw this code while studying the wordpress source code (PHP), You can
Saw this piece of code in a Ruby on Rails book. This first one

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.