tags:

views:

129

answers:

3

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?

+1  A: 

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 … });
Reinis I.
A: 

i don't know what your requirements are but you might be asking about a .live event.

http://docs.jquery.com/Events/live

CurlyFro
A: 

Do this:

$('#anElement').append(theHTML).find('#newElement').listener(function(){ 
    // Some code 
});

listener being the event (ie: click, hover, etc...)

a432511