I use jQuery to attach some plugins in the $ (document) .ready () handler - for example, $ (". Date"). datepicker (). However, when I load content using $ ("... html ..."), for example, from $ .ajax (.., success (data) {}) or from ajaxForm ({target: ...}) , document.ready () is obviously not being called. UPDATE: as indicated, it is calledbut still I donβt know which part / element was loaded.
I cannot just do ready () again, because it will reconnect the plugins to the existing elements again. Therefore, I must do this manually in each case, for example, I am doing successful (data) {item = $ (data); initDatePickerEtc (item); }.
Is there a better way?
There's a Live Query plugin that does this for events. Is there something that will allow me to track the creation of HTML elements and perform actions? Sort of
$.oncreation(".date", function() { $(this).datepicker(); });
$.oncreation(function() { $(this).find(".date").datepicker(); });
Itβs great if it also processes existing elements ... for example, Live Query works both for existing elements during the click () call and for elements created in the future.
Please note that I will be happy to track only elements created by jQuery. Thus, either jQuery provides an extension point for its html () function or not, I think. Now from jQuery sources this is not happening:
html: function( value ) {
return value === undefined ?
(this[0] ?
this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") :
null) :
this.empty().append( value );
},
, html() , 3- (, ajaxForm) ( $.creation), jQuery... ? - html(), append() ..... , $("")... datepicker().