views:

25

answers:

4

there are plugins such as flowplayer overlay that asks to put a "rel" attribute to the HTML element to make it trigger certain events ... the problem is , when I create dynamically elements that have that rel attribute ,, they won't trigger it ... what is the solution for this !?

A: 

Edit the plugin so it uses live() to handle events.

David Dorward
A: 

Generally, there is the jQuery live() function to address exactly this kind of issue.

You would have to change the plugin to use live(), or run their initialization function every time new content is added.

The latter approach can be pretty resource-intensive on the client end and is not very clean, but if the number of elements in question is not too much, it can often be the easiest way.

Pekka
+2  A: 

You should use the live() method to trigger events for dynamically created elements.

Example:

$('selector').live('click', function(){
  // your code .........................
});
Sarfraz
+2  A: 

Since jQuery 1.4.2 you can also use .delegate():

Description: Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.

The use of delegate can sometimes result in less and more understandable code than .live().

Felix Kling