javascript - Jquery - (re)wiring dynamically generated elements -


Often times I've added elements such as the added task: such as:

  $ ('. Myfav') autocomplete () .; $ ('. Myfav') datepicker () .; Click on $ ('. MyFav') (somefunction).  

But when more examples of this class are dynamically generated through some code, the new $ ('. Myfav') is dead. Rewireing is needed again, so I do it:

  $ ("# somelink"). Click (function () (// generate 10 new $ ('. Myfav') and add them to DOM / re-wire again as block above ($ .MyFav '), auto-integer ( ); $ ('. MyFav'). Date picture (); $ ('. MyFav'). Click (no function);});  

This means that I end up for two identical blocks of code, 1 initial page load and are dynamically generated to retrieve a new element. This is not a dry code and it is not very efficient.

Is this really the only way to do this, or is there another best practice? My stomach tells me that it should be more efficient (also to help the code dry)

Update

It seems that. Click as explained by Cleitus.

  $ ('. MyFav'). Live ("click", a function);  

But I tried it with a custom-set plugin. Auto complete and it does not work. I tried to do this:

  $ ('. MyFav'). Live ("click", auto complete ("somefile.php", {max: 15, matched: true}));  

So it does not seem that it can handle these custom plugins (of course I may be wrong, please update if you know something)

.live () Documentation says ...

.live no event style callback support That liveQuery provides only the event operators can be bound with .live.

So I took a look, and I think it will really need something with you:

  $ ('. MyFav') .livequery (function () ($) () () (); $ (this) .data picture (); $ (this). Click (no function);});  

Looks easy!


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -