Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery plugin .live() to .on()

How to change

$.fn.ajaxFormPostLink = function() {    
    this.live('click', function() {
        var $this = $(this);

...

to somenthig using .on() not .live(), i tried:

$.fn.ajaxFormPostLink = function() {    
    $("body").on('click', this, function() {
        var $this = $(this);

...

but id does not work, so how to change live() to on() in jQuery plugin.

like image 534
Dariusz Męciński Avatar asked May 06 '26 16:05

Dariusz Męciński


2 Answers

Rebuild the plugin to be used this way:

$.ajaxFormPostLink(".someform",{... options ...});

for example:

$.ajaxFormPostLink = function(selector,options) {

    $(document).on("click",selector,function(){
        ...
    });

};
like image 52
Kevin B Avatar answered May 09 '26 12:05

Kevin B


Try this:

$("body").on('click', this.selector, function() {

Assuming you are dealing with simple jQuery object.

like image 27
freakish Avatar answered May 09 '26 10:05

freakish



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!