Dariusz Męciński
Dariusz Męciński

Reputation: 31

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.

Upvotes: 3

Views: 93

Answers (2)

Kevin B
Kevin B

Reputation: 95023

Rebuild the plugin to be used this way:

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

for example:

$.ajaxFormPostLink = function(selector,options) {

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

};

Upvotes: 3

freakish
freakish

Reputation: 56467

Try this:

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

Assuming you are dealing with simple jQuery object.

Upvotes: 1

Related Questions