0

I would like everytime I call a jquery load function:

$("#div").load("file.php");

To then call a separate function:

function secondFunction() {
    //do stuff
}
Colin Brock
  • 20,857
  • 9
  • 45
  • 61
Olokoo
  • 1,114
  • 3
  • 18
  • 34
  • 1
    This might help: http://stackoverflow.com/questions/296667/overriding-a-javascript-function-while-referencing-the-original – David Burhans Jan 24 '12 at 18:08
  • Do you want it for `load`function only or are you asking for a more general answer? the `load` function has a callback parameter. – gdoron is supporting Monica Jan 24 '12 at 18:09
  • I want it to be separate from the place where i call the load. So i need something that almost checks to see if there is a load and then calls it every time the something is loaded. @gdoron – Olokoo Jan 24 '12 at 18:20

2 Answers2

3

Pass it as the callback:

$("#div").load("file.php", secondFunction);
gen_Eric
  • 214,658
  • 40
  • 293
  • 332
  • @Ian34: When exactly do you want it to run? There's no event that's triggered when `load` is called, or something like that. What's wrong with using the callback function? – gen_Eric Jan 24 '12 at 18:50
1

if i have understood clearly you can call the second function as the call back each time load is called

$("#div").load("file.php",secondFunction);
Rafay
  • 30,714
  • 5
  • 66
  • 99