tags:

views:

126

answers:

2

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!

+1  A: 

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

Tatu Ulmanen
no this doesn't work, because $f must be called for an event. there are references to this inside it.
dharga
A: 

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

added:

$foo.change();

after $foo.change($f).

dharga
If you want to go that way, instead of `trigger`, you can just do `$foo.change()` to execute the function binded to the element's change event.
Tatu Ulmanen
yep, i just found that also. i'm VERY new to jQuery. i'm working with a web dev who's used it before. so we're learning a lot as we go here.
dharga