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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:15:34+00:00 2026-05-26T03:15:34+00:00

Why this works in jQuery : $(‘#selCars’).change(function(){ alert( I have changed! ); }) but

  • 0

Why this works in jQuery :

$('#selCars').change(function(){
     alert( "I have changed!" );
}) 

but not this one :

$('#selCars').change(alert( "I have changed!" ) ); 
  • 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-26T03:15:34+00:00Added an answer on May 26, 2026 at 3:15 am

    You pass a function reference to .change(). Your second example just has code there, not a function reference.

    Your first example works because it passes a function reference which IS what is required.

    A function reference is required because this is a callback that will be called at a later time. The .change() function which executes immediately needs to save the callback reference into it’s own variable and then call it later when the change event actually occurs. To do that, it needs a function to call at that later time, not a raw piece of code.

    And, the other answer is because, .change() was written to require a function reference. That’s how the developers that spec’ed and wrote it designed it. If you want it to work, you have to follow their rules.

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

Sidebar

Related Questions

This works in jQuery 1.3.2, but not in 1.4 $(#container).children().map(function() { var child =
I have this jQuery which works fine $(li[id^='shop_id']).click( function () { alert(I clicked on
<script type=text/javascript> $(document).ready(function() { alert(Hello jQuery.); }); </script> This works the first time I
Hi have the following function which works fine: jQuery('.btnRemoveItem').click(function(obj){ jQuery(this).closest('li').fadeOut(400, function() { $(this).remove(); });
I have a jQuery plugin that I am using: $(document).ready(function(){ $('.elements').fancyPlugin(); }); This works
This works in Drupal 7: jQuery(document).ready(function myfunction($) { }); But what is the syntax
I am using this jquery function that works fine in win/mac FF 3.5 and
I have run into this jquery plugin and i quite understand how this works:
I make use of class selectors in JQuery and this works fine but in
I add html to a page using JQuery's html() function. This works great on

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.