Is there a variant of the jQuery live () function that is not event bound?

Is there a variant of the jQuery live () function that is not event bound?

For example, I would like to do something like this:

$('.jdate').live(function() {
    var datebox = $(this);
    datebox.datepicker();
    //do a couple more things 
}

therefore, all .jdate fields that are on the form and those that are added later through ajax are handled the same way.

+3
source share
3 answers

Although the plugin livequerythat @jAndy (or should I say @jAndy ) will work, I believe this is a last resort because of the overhead that is required.

If you add new elements to the DOM, you should simply call the plugin for these new elements when you add them.

$.ajax({
    url:'/some/path/',
    success:function(resp) {
        var $resp = $( resp );
        $resp.find('.jdate').datepicker();
        $resp.appendTo('#myform');
    }
});
+1
source

Place an order jQuery livequery plugin what is it for this purpose.

+4
source

, , :

$('.jdate').live('customEvent', function() {
    var datebox = $(this);
    datebox.datepicker();
    //do a couple more things 
});
$(function(){
    $('.jdate').trigger('customEvent');
});
+1

Source: https://habr.com/ru/post/1788286/


All Articles