javascript function doesn't call in internal page on click of link yii CListView

i am using CListView in my one of form. i used CHtml::link in one of column. and its html is like this


<a class="text-dark" value="31" href="javascript:void(0)" title="You received a new message">

and onclick of this link i called one javascript function

following function




$('a.text-dark').click(function()

    {


        var id = $(this).attr('value');


        $.ajax({

                        type:'POST',

                        url:'<?php echo Yii::app()->createUrl('/mailbox/message/View') ?>/id/'+id,

                        success:function(data){ 


                                   },

                        error:function(data){ 

                                        alert('Your data has not been submitted..Please try again');

                                          }


          });

    });



My main issue is on first page it works perfect. function is called perfectly. but whenever i click on next button from pagination and click on this link. function is not called. Except One page any page doesn’t call function. What is problem?

switching pages use background ajax request and then replacing CListView container DIV with new content. Problem is that your jquery function is called only once on main page load and does not apply to newly loaded content.

Try to provide javascript handler for afterajaxUpdate (http://www.yiiframework.com/doc/api/1.1/CListView#afterAjaxUpdate-detail) or use

$(‘a.text-dark’).live(‘click’, function()…

or .on() function in jQuery >=1.7 (as manual suggest) https://api.jquery.com/on/#on-events-selector-data-handler:

jQuery(document).on( eventName, selector, function(){} );

Thanx a lot. it helps me. works perfect. :rolleyes: