Problem With Pjax

I have a site.js script file and added it to AppAsset.

I put my view in a Pjax block. a DataGrid and a Form are in view.

in view:

<div id="testJS" class="well">

    click for test


in site.js:


    alert("test OK");


it’s work fine before any pjax action.

after any pjax request (for example go to page2 of datagrid) it’s not working.

The event will be lost when the html is reloaded.

You’ll need to attach the event to something that doesn’t change with ajax.

$('#container').on('click', '#testJS', function() {});

first there is no reload on html but replace.

second the event of $(’#testJS’).click occurred after pjax:success event