0

As Jquery 1.9 deprecated live() function,So I have to change those to alternative on().

Everything seems fine.

In my project i am using almost >100 live() functions.They should work great if I go there each place and change to on().

Is there any efficiant way or script to use on() function,where ever i am using live() now ??

This would save lots of my time.

Please suggest any other options too.

Thank.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • 2
    Take a look at [jQuery 1.7 - Turning live() into on()](http://stackoverflow.com/questions/8021436/jquery-1-7-turning-live-into-on) and see [this answer](http://stackoverflow.com/a/15549448/1493698). – Antony May 06 '13 at 06:31
  • 1
    Are you wanting to make each `.live()` call continue to work by calling `.on()` in turn? Or are you wanting to do a *search and replace* so you're no longer using `.live()` at all? – Jonathan Lonowski May 06 '13 at 06:36
  • @JonathanLonowski yeah,If i do search and replace, if any other text is there named as live it will replace there also and it may cause some other troubles for me. – Suresh Atta May 06 '13 at 06:38
  • 1
    Regex-based search and replace shouldn't have such a problem. – Fabrício Matté May 06 '13 at 06:39
  • @JonathanLonowski yeah,that is a better option,but i done that 50 funtions and made a question for remaining 200 function :) well as eli suggested will try migrated script if it is light weight otherwise will do the same as you suggested.thanks dear :) – Suresh Atta May 06 '13 at 06:46

2 Answers2

2

You can try to use jQuery migrate which is used to detect and restore APIs or features that have been deprecated in jQuery and removed as of version 1.9.

Eli
  • 14,779
  • 5
  • 59
  • 77
1

May be you can tweak this a lil bit!

just extend jquery with a .live() function by your own which internally points to .on().

    (function(jQuery) {
        // Store a reference to the original remove method.
        var originalOnMethod = jQuery.fn.on;

        // Define overriding method.
        jQuery.fn.live = function() {
            // event is bind for the elements added dynamically as well. 
            if(typeof arguments[0] == "string" && typeof arguments[1] == "function"){
                $(document).on(arguments[0], this.selector, arguments[1]);
            }else{//applied when proper live syntax is not followed and event will not fire for dynamically added elements  
                originalRemoveMethod.apply( this, arguments );
            }

        }
    })(jQuery);

I just created this function and tested, it works but you never know where it breaks. Do reply if it needs anything to coagulate. Thanks! :-)

Sai Chaithanya
  • 708
  • 1
  • 7
  • 14