dharga
dharga

Reputation: 2217

JQuery executing onLoad

So I'm trying to execute a function on a component when the page loads. This is what I have so far.

$(document).ready(function() {
  var $foo = $('#data_lost').hide();

  $f = function () {
    doSomething...
  };

  $foo.change($f);
});

So this all works fine and dandy. Here's the problem. I also need $f executed on $foo when the page loads. I tried setting $foo.ready($f), but that doesn't work. I tried setting it inside and outside of document.ready(). Neither options work. I'm assuming that doing it outside doesn't work because the tag doesn't exist until document is ready, and doing it inside doesn't work because when the document is ready, the tag has already become ready, so it won't ever be ready again, so $f isn't called.

Ideas??

TIA!

Upvotes: 0

Views: 700

Answers (2)

dharga
dharga

Reputation: 2217

Well, goes to show...you ask...fate has it that you find your own answer soon after...

added:

$foo.change();

after $foo.change($f).

Upvotes: 0

Tatu Ulmanen
Tatu Ulmanen

Reputation: 124768

You can just do $f(); inside the ready block to execute your function on page load.

Upvotes: 1

Related Questions