2

Can we use the on() function instead of livequery plugin? If it is possible, how can I use the on() here;

$('.layout_block').livequery(function(){
    $(this).resizable({
        // ...
    });
});
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
user1915190
  • 307
  • 1
  • 2
  • 14
  • 4
    No, you can't, because they do different things. Related: http://stackoverflow.com/q/12332482/218196. Maybe also relevant: http://stackoverflow.com/q/7675526/218196. – Felix Kling Apr 24 '13 at 06:13
  • Thanks for the links. Is there any other ways to do this with jquery events? – user1915190 Apr 24 '13 at 06:33

1 Answers1

-1

According the documentation you can bind a click event for example.

$('a').livequery('click', function(event) { 
   // your code
});

Since livequery is designed as a plugin to allow you to add the same event to dynamically added elements, it cannot be replaced with jQuery's default on() function. Otherwise, the plugin should be useless.

So to react on your comment...if you do not need livequery's functionality, do not use it and go for the native on() function.

Bas Slagter
  • 9,831
  • 7
  • 47
  • 78
  • There is no reason to use livequery for event handlers though, because that's what `.on` already can do itself (event delegation). – Felix Kling Apr 24 '13 at 06:28
  • 1
    Actually i want to use an event instead of the external plugin. – user1915190 Apr 24 '13 at 06:33
  • @BasSlagter I was reading https://learn.jquery.com/events/event-delegation/ and my impression was that jQuery's default on() function can be used as an equivalent to what the Live Query plugin does by creating a delegated event as they show in an example: $( "#list" ).on( "click", "a", function( event ) {}. Since modern versions of jQuery already do what the Live Query plugin does, the Live Query creator says this at https://github.com/brandonaaron/livequery: "In the rewrite the event binding functionality has been removed since jQuery provides really nice event delegation." – Jaime Montoya Sep 08 '17 at 00:27