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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:42:20+00:00 2026-05-27T10:42:20+00:00

I copied this example from api.jquery.com $(‘.target’).change(function() { alert(‘Handler for .change() called.’); }); I

  • 0

I copied this example from api.jquery.com

$('.target').change(function() {
  alert('Handler for .change() called.');
});

I also tried:

$('#target').change(function() {
  alert('Handler for .change() called.');
});

I copied it into my .js file, which is included in my html. I have another jQuery function in there (beginning $(window).load(function () { …”

The other function is working. But the above simple function is not.

The form looks like this:

<form>
    <select id="target" class="target">
        <option name="pp" value="6">6</option>
        <option name="pp" value="12">12</option>
    </select>
 </form>

I want to just use id, but I added class just for testing. But neither works.

Why doesn’t this simple function work? Do I need to do anything else to connect the change event to the function? I am new to jQuery, but I know that in javascript I would have to have the onchange event of the form call the function in order for something to happen.

EDIT: Ok, here is EVERYTHING in my included .js file. As you can see, just one other function. Is it interfering?
Also, I have only 1 form on the page, which you see above. I am going to have it change the number of results shown per page (6 or 12).

$(window).load(function() {
    $("img.gall_img").each(function() { // iterate through all img of class gall_img
        var imgWidth = $(this).width(); // "$(this)" to access jQuery width() func
        var divWidth = $(this).closest('div').width();
        //alert(imgWidth + " and " + divWidth); // for debugging
        if(imgWidth > divWidth) {
            var position = Math.round(-1 * ((imgWidth/2) - (divWidth/2))); // 
            position = position + "px"; // make position format "123px".
                $(this).css("left", position); // "$(this)" to access jQuery css() func
            }
    });
});


$("#target").change(function() {
  alert('Handler for .change() called.');
});
  • 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-27T10:42:21+00:00Added an answer on May 27, 2026 at 10:42 am

    Put the code inside the $(window).load function, like so:

    $(window).load(function () {
    
    //whatever code is already here
    
    $('.target').change(function() {
      alert('Handler for .change() called.');
    });
    
    }); //end of $(window).load function
    

    $(window).load(function () tells the browser to only run that code after the entire page is loaded INCLUDING images. Traditionally with jQuery you will see the $(document).ready(function() {… which tells the browser to not process that code until after the page is loaded (not including images)

    IF you don’t need to wait for the images to load to run your jQuery then you could replace $(window).load(function () { with $(document).ready(function () {

    Cheers!

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

Sidebar

Related Questions

I copied this code from an example . I've read it 100 times. Array.prototype.map
this is copied from http://www.zenspider.com/ZSS/Products/RubyInline/Readme.html , the home of rubyinline, adding/moding as indicated in
I copied this example from perldoc -f sort . I added the @old array
I'm at a loss debugging this code. I copied the example from a guide,
I copied the example from http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first and saved it locally to test.html on my
This is copied ditto from example given in Sql2008 R2 doc - Syntax: DATENAME
I'm using jQuery v1.5.1 and jQuery Cycle v2.99 with the code from this example
I copied this code from another post. I tried the example, however, I am
This example below illustrates how to prevent derived class from being copied. It's based
I copied this example from this topic. It's better to release the ivar directly.

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.