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 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. But I tried it with a custom-set plugin. Auto complete and it does not work. I tried to do this: So it does not seem that it can handle these custom plugins (of course I may be wrong, please update if you know something) $ ('. 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);});
$ ('. MyFav'). Live ("click", a function);
$ ('. MyFav'). Live ("click", auto complete ("somefile.php", {max: 15, matched: true}));
.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
Post a Comment