JQuery delegates with plugins

jQuery delegates are great, especially when used with table row click events.

I was wondering if delegates with plugins can be used?

For example, if I attach an elastic plugin to each text area, I would do:

$("textarea").elastic();

But how can I connect this plugin using a delegate?

+3
source share
2 answers

You can cheat. Well, you can in this case.

You need an event that can delegate, which will always happen before the plugin needs to be applied, and some ways to find out if it really was. You can always add this yourself, though.

Assuming you are using this plugin:

http://www.unwrongest.com/projects/elastic/

, / , :

$('textarea').live( 'focus', function(){
   if( !$(this).data('iselastic') )
      $(this).data('iselastic', true).elastic();
})

, jQuery 1.4 .

+4

, , . Live .

+4

Source: https://habr.com/ru/post/1746006/


All Articles