Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a variant of jQuery's live() function that does not bind to events?

Tags:

jquery

Is there a variant of jQuery's live() function that does not bind to events?

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

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

so all '.jdate' fields that are in the form and the ones that are added later through ajax are treated the same.

like image 681
wusher Avatar asked Dec 14 '25 08:12

wusher


2 Answers

Checkout the jQuery livequery pluginwhat is this for that purpose.

like image 67
jAndy Avatar answered Dec 16 '25 23:12

jAndy


Although the livequery plugin that @jAndy (or should I say @jAndy) mentioned will work, I'd consider it to be a last resort because of the overhead it requires.

If you're adding new elements to the DOM, you should simply call the plugin on those new elements when you add them.

$.ajax({
    url:'/some/path/',
    success:function(resp) {
        var $resp = $( resp );
        $resp.find('.jdate').datepicker();
        $resp.appendTo('#myform');
    }
});
like image 43
user113716 Avatar answered Dec 16 '25 23:12

user113716



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!