Will
Will

Reputation: 2358

Is there a way to fire jQuery's live() or delegate() without a user event?

I am trying use jQuery to poll dynamic DOM nodes, created outside of the jQuery object (with Google Maps API methods). I can do this easily by, for example, binding delegate() to a click event. However, I need to poll the DOM, without any additional user actions (user should not have to click), as part of a function that runs onload. Does anyone know of a way to accomplish this?

Edit: I'm using the Maps API to write add a bunch of markers at load. I can do this without any problems, but I need to loop through the HTML the Maps API writes with jQuery and append child nodes. delegate() and live() can this, but the only way I know how to fire delegate() or live() is by binding it to an user event. I'm trying to fire off something like jQuery's delegate with each iteration of my Maps API function, without the user doing anything.

Upvotes: 2

Views: 2212

Answers (2)

leek
leek

Reputation: 12131

Check out the LiveQuery plugin. Here is a simple example of its use:

$('table tr:even').livequery(function(){
    $(this).removeClass("odd");
    $(this).addClass("even");
});

This snippet would automatically apply the "even" class and remove any "odd" class that might be on a table row dynamically as new rows are added to the table.

Upvotes: 3

harpax
harpax

Reputation: 6116

do the call once:

setTimeout("doGoogleMapApiCall()", 5000);

.. or multiple times:

setInterval("doGoogleMapApiCall()", 5000);

EDIT: I think what you are looking for is a custom event? Have a look here: http://www.reynoldsftw.com/2009/04/custom-events-in-jquery-open-doors-to-complex-behaviors/

Upvotes: 0

Related Questions