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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:16:44+00:00 2026-05-31T03:16:44+00:00

<button onclick=$.MyObject.add(‘wrapper’);>Add</button> Somewhere in the code I did: $.MyObject= new MyUberObject(); then in my

  • 0
<button onclick="$.MyObject.add('wrapper');">Add</button>

Somewhere in the code I did:

$.MyObject= new MyUberObject();

then in my add function, I specify my call back, and invoke the animation and pass my callback to it.

function MyUberObject(data) {
  ...
  this.add = function(name, index) {
     var callback = function(n,i) { 
              $.MyObject.addDiv(n, i); 
              alert("wtf");
           }(name, index);

     $("#outerWrapper").animate(
        {
           "width": "+=200px",             
        }, 
        {
           duration : "fast",
           easing: "linear",
           complete: callback
        }               
     );
  ...
}

However the alert come up immediately as soon as the button is pressed, then once I cleared the alert, the animation would go… I’ve tried many different ways of specifying the callback, as well as try to use delay and call it in other places… still no go.

  • 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-31T03:16:46+00:00Added an answer on May 31, 2026 at 3:16 am
     var callback = function(n,i) { 
              $.MyObject.addDiv(n, i); 
              alert("wtf");
           }(name, index);
    

    You are calling the callback here, that’s why it’s getting called.

    Try doing this, I think name and index should exist due to closure.

    function MyUberObject(data) {
      ...
      this.add = function(name, index) {
    
         var callback = function() { 
                  $.MyObject.addDiv(name, index); 
                  alert("wtf");
               };
    
         $("#outerWrapper").animate(
            {
               "width": "+=200px",             
            }, 
            {
               duration : "fast",
               easing: "linear",
               complete: callback
            }               
         );
      ...
    }
    

    if not then you can add the name and index to the outerwrapper:

    function MyUberObject(data) {
      ...
      this.add = function(name, index) {
    
         var callback = function() { 
                  $.MyObject.addDiv($(this).data("props").name, $(this).data("props").index); 
                  alert("wtf");
               };
    
         $("#outerWrapper").data("props", {name : name, index : index};
         $("#outerWrapper").animate(
            {
               "width": "+=200px",             
            }, 
            {
               duration : "fast",
               easing: "linear",
               complete: callback
            }               
         );
      ...
    }
    

    or maybe even simpler…

    function MyUberObject(data) {
      ...
      this.add = function(name, index) {
    
         var callback = function(n, i) { 
                  $.MyObject.addDiv(n, i); 
                  alert("wtf");
               };
    
         $("#outerWrapper").animate(
            {
               "width": "+=200px",             
            }, 
            {
               duration : "fast",
               easing: "linear",
               complete: function(){callback(name, index);}
            }               
         );
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this solution for a single button: myButton.Attributes.Add(onclick, this.disabled=true; + GetPostBackEventReference(myButton).ToString()); Which works
I'm trying to add a button onclick event to a button tag when I
I have this code to check/uncheck a radio button onclick. I know it is
when ever i call a JavaScript function from asp:button onclick event i got this
Why doesn't this work? <button onclick = function(){alert('Hello');}>press me</button> while this does: <button onclick
how to handle button onclick action in iPhone without using interface builder?
I'm trying to get a specific asp:button onclick event to fire when I press
I have an asp button with no onclick event but only onclientclick. This call
I have a button. Its OnClick event calls a procedure which destroys the button,
What is the difference between using the OnClick attribute of an ASP.Net Button: <asp:Button

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.