简体   繁体   中英

jQuery isn't working after an AJAX query

I have a problem with my jQuery code. I have a div that is hidden and when the mouse hovers a sibling of this div , is shown. But when my AJAX function is called, jQuery isn't working.

<div class="parent">
     <div class="theDiv" style="display:none">
     </div>
     <div class="sibling">
     </div>
</div>
$('.sibling').hover(function(){
  $(this).parent().find('.theDiv').fadeIn('fast');
});

$('.catFilterSelect').change(function(){
    $.ajax({
    url:"load_data.php",
    method:"POST",
    data:{
      reg:a,
      price:b,
      type:c,
      subject:d,
      city:e,
      typeSubject:typeSubject
    },
    dataType:"text",
    success:function(data){
      $('.catPostsBox .catPost').remove();
      $('.catPostsBox').append(data);
    }
  });
})

This script works before AJAX, but after that doesn't work

<div class="parent">
     <div class="theDiv" style="display:none">
     </div>
     <div class="sibling">
     </div>
</div>
<script>
$(function(){
     $('.sibling').hover(function(){
           $(this).parent().find('.theDiv').fadeIn('fast');
     });
});
or -- both are same
$(document.ready(function(){
     $('.sibling').hover(function(){
           $(this).parent().find('.theDiv').fadeIn('fast');
     });
});

</script>
<script>
$(function(){
$('.catFilterSelect').change(function(){
    $.ajax({
    url:"load_data.php",
    method:"POST",
    data:{
      reg:a,
      price:b,
      type:c,
      subject:d,
      city:e,
      typeSubject:typeSubject
    },
    dataType:"text",
    success:function(data){
      $('.catPostsBox .catPost').remove();
      $('.catPostsBox').append(data);
    }
  });
})
)};
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM