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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:16:13+00:00 2026-06-15T13:16:13+00:00

I have a piece of code that works well but I cannot get the

  • 0

I have a piece of code that works well but I cannot get the idea behind part of it, so any help is appreciated.

In the following function what does the bind(this) function do at the end of code? I have searched a lot both SO and JQuery documentation but couldn’t find any usage like that. All usages of bind() try to hook up a function to an event but here bind is called after a function and passed a JQuery object (which is an img tag in this case). Thanks in advance.

function refreshCaptcha() {
    var currCaptcha = $('#captcha-div img');

    currCaptcha.animate({
        opacity: 0.3
    }, 300);

    $.getJSON("/captcha.json", function (data) {
        var src = $("#captcha-template").html();
        var template = Handlebars.compile(src);
        var newSrc = template(data);
        var srcDom = $(newSrc);

        srcDom.eq(0).css('opacity', 0).load(function() {

            currCaptcha.animate({
                opacity: 0
            }, 250, function() {
                $("#captcha-div").html(srcDom);

                $(this).animate({
                    opacity: 1
                }, 250);

            }.bind(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-06-15T13:16:15+00:00Added an answer on June 15, 2026 at 1:16 pm

    bind creates a new function which, when invoked, has its this value set to the first argument passed. So in this case, the animate callback will have its context set to srcDom.eq(0) when invoked.

        srcDom.eq(0).css('opacity', 0).load(function() {
    
            // In here, the value of "this" is srcDom.eq(0)
    
            currCaptcha.animate({
                opacity: 0
            }, 250, function() {
                $("#captcha-div").html(srcDom);
    
                $(this).animate({
                    opacity: 1
                }, 250);
    
            }.bind(this)); /*When that callback is invoked, all 
                             occurrences of "this" inside it will refer 
                             to srcDom.eq(0)*/
    
        });
    

    More on this here

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

Sidebar

Related Questions

I have this piece of code that works fine in subsonic 2.2, I migrated
I have a small piece of code that works as a plugin for a
I have a Image XML menu that works well, but with a litle problem
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have a piece of code here that does not work despite me using
I have the following piece of code that takes in some words, stores them
I have a piece of code ( I'm student ) that should work in
I have a piece of code that was written by someone else before the
I have a piece of code that load a very big image in memory.
I have a piece of code that takes several rows from a database and

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.