Reputation: 1533
I did similar things with this before:
$.append(html,listener);
This will work for me because the listener will be added AFTER html is loaded.
And I can't do this:
$.html(html);
listener();
Because this way I can't ensure html is loaded.
How to do it the right way?
Upvotes: 1
Views: 1657
Reputation: 1905
Do this:
$('#anElement').append(theHTML).find('#newElement').listener(function(){
// Some code
});
listener being the event (ie: click, hover, etc...)
Upvotes: 2
Reputation: 1882
i don't know what your requirements are but you might be asking about a .live event.
http://docs.jquery.com/Events/live
Upvotes: 1
Reputation: 8158
Your question is somewhat unclear, but I'm guessing you want the 'ready' event. It fires when the DOM is ready to be used. You use it like this:
$(document).ready(function() { … do whatever … });
Or this:
$(function() { … do whatever … });
Upvotes: 1