Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when a function's work is completed

I'm using a jQuery plugin, it gets data from an url, fetches, calculates and writes some data in a div.

I want to copy this div contents to another div, when that functions do its work.

for example:

$("#div1").myfunction(); // it gets and calculates data and adds to #div1 . it needs 2-3 seconds to be done
var contents = $("#div1").html(); // when myfunction() done, copy contents
$("#div2").html(contents);

when i ran that code, i didn't have new contents in #div2.

like image 651
mrdaliri Avatar asked Aug 23 '11 01:08

mrdaliri


People also ask

How is work function measured?

The work function is the minimum energy required to take out one electron through the surface. It can be measured by analyzing the slowest electrons emitted from the substrate applied with excess energy.

What is the photoelectric work function?

The photoelectric work function is the minimum photon energy required to liberate an electron from a substance, in the photoelectric effect. If the photon's energy is greater than the substance's work function, photoelectric emission occurs and the electron is liberated from the surface.

Why is work done a path function?

Heat and work are forms of energy that are in motion. They exist only when there is a change in the state of system and surroundings. In other words, they are non-existent before and after the change of state. Therefore, the work done is a path function.


1 Answers

you need to have myfunction take a callback parameter which it executes once the request is done

function myfunction(cb)
    $.ajax({
        type: "get",
        url: "page.html",
        success: function(data){
            $("#div1").html(data);
            if(typeof cb === 'function') cb();
        }
    });
}

myfunction(function(){
    $("#div2").html($("#div1").html());
});
like image 135
Ilia Choly Avatar answered Oct 27 '22 10:10

Ilia Choly