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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:14:39+00:00 2026-06-16T05:14:39+00:00

in my html page, i have an image, and on clicking a button, i’m

  • 0

in my html page, i have an image, and on clicking a button, i’m calling the function TestLoad() where it is changing the src of the image and when the image is loaded i’m doing something…
take an example:
javascript:

function TestLoad() {

    alert('before');
     $('#ImgTest').attr('src', 'Images/Image1.jpg');

     $('#ImgTest').load(function () {
         alert('after');
     });
}

html:

 <img id = "ImgTest" alt="" src="" style="width:100px; height:100px"/> 

 <input type="button" onclick ="TestLoad();" value="TestLoad"/>

my problem is:
when i click the button for the first time, i’m getting the alert “after” one time and if i click another time, the alert will be displayed two time and the third, 3 times…

Kindly advice
Thanks

  • 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-16T05:14:40+00:00Added an answer on June 16, 2026 at 5:14 am

    Each time your handler executes, it adds another new load handler. You only need to assign the handler a single time. If you really need to do it this way, you can either remove the existing handlers first or check the events to see if it’s already being handled:

    var $imgTest = $('#ImgTest');
    
    $imgTest.attr('src','Images/Image1.jpg');
    $imgTest.unbind('load');
    $imgTest.load(function(){
        alert('after');
    });
    

    Or:

    var events;
    var $imgTest = $('#ImgTest');
    
    $imgTest.attr('src', 'Images/Image1.jpg');
    events = $imgTest.data('events');
    if(events !== null && typeof events.load === undefined){
        $imgTest.load(function(){
            alert('after');
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few html image tags that fill an array. On the page
In a simple html page I have: <SCRIPT> function Clicker(number){ if (number == 1)
I have HTML similar to the following in my page <div id=someDiv> <img src=foo.gif
I have click-able images in my html page that call a javascript function... however
Below is the Html button and javascript function I have which closes a modal
I have a page in HTML(index.html), and a folders named images, css, js that
in my html page I have div with css: padding: 0px; color: rgb(51, 51,
Suppose on my HTML page I have many href s to a link. Using
I have HTML page where windows media player is embedded. It works very well
I have HTML page with some HTML element with ID=logo . I need to

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.