I use CListView,

I add new items to it and update it using: $.fn.yiiListView.update

everything goes fine, except…

inside the items of the CListView there are links like:

<?php echo CHtml::link( 'Create a new model', array( 'task/create','type'=>'','parent_id'=>$data->id), array(

  'class' => 'update-dialog-create' ,  

    ) ); ?>

and I use this code to add jquery behaviour to this link as following:

jQuery( function($){

  $( 'a.update-dialog-create' ).bind( 'click', updateDialogCreate );


again, so far every thing goes fine, except…

when $.fn.yiiListView.update updates the CListView the jquery bind goes away and the link becomes without the jquery behaviour.

to try to solve the problemm I tried many many things all wend in vain.

for example I tried to include the bind function inside the CListView, but all did not work.

I hope I am expressive enough and will get some help here.

Instead of bind, that works only with current elements, use live - live works with future elements

One solution for your problem would be to use the jquery live or delegeate methods.

Another solution: Bind your click event to a parent node of you list view and let the click event bubble up. This parent node have to be always on your page and shouldn’t be affected by any AJAX updates you do on your list view.



    var t = $(e.target);

    if (t.is('.update-dialog-create')) {

      // do your click logic here



See google: jquery event bubbling

to solve the problem I used this:

I added an onclick as follows:

<?php echo CHtml::link( ‘Create a new model’, array( ‘task/create’,‘type’=>’’,‘parent_id’=>$data->id), array(

‘class’ => ‘update-dialog-create’ ,

‘onClick’ => " updateDialogActionBase(‘task/create’, ‘Create’ );}"

) ); ?&gt;&lt;br&gt;

but it did not work unfortunately.

fortunately a friend Andrius Marcinkevicius, took a little look at the problem and advised me to use .live instead of .bind, and then the onclick worked fine.

now the problem is solved :)

@mdomba , @kokomo

thank you both very very much

by the way, .live alone did not work. it works only when I add the onclick

can anybody help me replace the onclick method with a valid href ?

<?php echo CHtml::link( ‘Create a new model’, array( ‘task/create’,‘type’=>’’,‘parent_id’=>$data->id), array(

‘class’ => ‘update-dialog-create’ ,

‘onClick’ => " updateDialogActionBase(‘task/create’, ‘Create’ );}"

) ); ?&gt;&lt;br&gt;

In your original code posted in the first post changing bind to live would work

jQuery( function($){

  $( 'a.update-dialog-create' ).live( 'click', updateDialogCreate );