Jquery events not working on ajax loaded content

后端 未结 2 1158
我寻月下人不归
我寻月下人不归 2020-12-14 08:57

The below code works. If there is some better way please let me know. If i use the script content which is present in test.html in the main page where I am loading test.html

2条回答
  •  甜味超标
    2020-12-14 09:19

    One option is to initialize your script on load success:

    $('.test').on('click',function(){
       $('#ajaxload').load('test.html',function(){
          $('body').on('click', '.heading', function(){
              $(this).css('color','red');  
          }); 
        });
     });
    

提交回复
热议问题