jquery - facebox not working after $.post -


i'm using facebox open remote page, includedjquery, facebox.js , facebox.css , put in document.ready

jquery(document).ready(function ($) {  $('a[rel*=facebox]').facebox({     loadingimage: 'imgs/loading.gif',     closeimage: 'imgs/closelabel.png'    }); }); 

everything works till call function

function lecfunc(year) {         var name = year + '_lec';         $.post('php/scripts/lecclickscript.php', { matyear: year, mattype: name      }, function (data) {             document.getelementbyid("lecs_tbody").innerhtml = data;             document.getelementbyid("lecs_boxbody").style.display = 'block';             document.getelementbyid("qus_boxbody").style.display = 'none';          });      } 

the facebox doesn't work more

edit :: solved
actully problem was using 2 jquery versions read qustion can-i-use-multiple-versions-of-jquery-on-the-same-page

then added code exact sequence

    <script src="js/jquery.js"></script>     <script type="text/javascript" src="js/facebox.js" ></script>     <script type="text/javascript" src="js/onclick.js" ></script>     <script>var $j = jquery.noconflict(true);</script>      <script src="plugins/jquery/jquery-2.1.3.min.js"></script>     <script>         $(document).ready(function () {             console.log($().jquery); // prints v2.1.3             console.log($j().jquery); // prints v1.4.2         });    </script> 

and in onclick.js file

jquery(document).ready(function ($) {      $('a[rel*=facebox]').facebox({         loadingimage: 'imgs/loading.gif',         closeimage: 'imgs/closelabel.png'     }); });    function lecfunc(year) {     var name = year + '_lec';     $.post('php/scripts/lecclickscript.php', { matyear: year, mattype: name }, function (data) {         document.getelementbyid("lecs_tbody").innerhtml = data;         document.getelementbyid("lecs_boxbody").style.display = 'block';         document.getelementbyid("qus_boxbody").style.display = 'none';          $j('a[rel*=facebox]').facebox({             loadingimage: 'imgs/loading.gif',             closeimage: 'imgs/closelabel.png'         });     });  } 

you're initializing facebox when page loaded. in case, facebox plugin applied elements available in dom. after insert content ajax, new content won't initializied facebox. in order make work, you'll have initialize after $.post, so:

jquery(document).ready(function ($) {     function facebox_init() {         $('a[rel*=facebox]').facebox({             loadingimage: 'imgs/loading.gif',             closeimage: 'imgs/closelabel.png'         });     } });  function lecfunc(year) {     var name = year + '_lec';     $.post('php/scripts/lecclickscript.php', { matyear: year, mattype: name }, function (data) {         document.getelementbyid("lecs_tbody").innerhtml = data;         document.getelementbyid("lecs_boxbody").style.display = 'block';         document.getelementbyid("qus_boxbody").style.display = 'none';          facebox_init();     }); } 

Popular posts from this blog