What's the cleanest way of executing something on an element that is dynamically loaded through js/jQuery? Basically the user adds a form that potentially has a wysiwyg editor in it (depending on the context); this is a textarea that needs to have something like $(".wysiwygTA").editor();
called on it. Of course I could do something like:
var newForm = 'some_form_loaded_via_ajax_with_a <textarea class="wysiwygTA"> in_it';
$(".formWrapper").append(newForm);
$(newForm).find(".wysiwygTA").each(function(){ $(this}.editor(); });
But that doesnt seem very clean to me. Ideally I want to do something in the fashion of
$(document).listenForAddedTextarea(function(textarea){textarea.edtior();});
So that I could add the form from multiple places. I could isolate the editor-invoke in a seperate function and just call that, but that still leaves me with an extra line of code each time I want to add an element.
So: what would be the best way around this? :o)
Best Regards,
Rasmus Dencker