jQuery events not happening after AJAX load?

前端 未结 8 682
别跟我提以往
别跟我提以往 2021-01-22 13:59

I have a website that will fade out a section of my website, load new content in, and fadeIn. There\'s a feature I had where a picture would get big when you click on it (it\'s

相关标签:
8条回答
  • 2021-01-22 14:41

    i would suggest checking out a jquery plugin called livequery

    with that you could replace:

    $(".makePictureBig").click(function() {
      //existing stuff
    

    with

    $(".makePictureBig").livequery(function() {
       $(this).click(function() {
       //existing stuff
    

    With livequery, anytime an element is placed into the dom that matches the selector, the callback function will fire.

    0 讨论(0)
  • 2021-01-22 14:42

    You need to re bind the events of the loaded elements.

    something like:

    document.getElementById('right_bar_wrapper').innerHTML = theRetrievedData;
    $(".makePictureBig").click(picBigFunction);
    
    0 讨论(0)
提交回复
热议问题