Call jquery function when
    content change

前端 未结 7 724
遇见更好的自我
遇见更好的自我 2021-01-17 08:40

I try to call jQuery function when ul content is changed.

Below is my code

JS

jQuery(document).ready(function($) {

        $(\'.ProductList\         


        
7条回答
  •  再見小時候
    2021-01-17 09:40

    Test that: {this won't work if specific ajax request is set to global false}

    ! function () {
        var ulContent;
        $(document).ajaxStop(function () {
            var $ul = $('.ProductList');
            if(ulContent !== $ul.html()){
                ulContent = $ul.html();
                $ul.trigger('contentChanged');
            }
        });
    }();
    
    $('.ProductList').on('contentChanged',callback);
    

    callback is the function you want to call when content of UL changed. You should just call it directly from ajaxStop handler but usually we use a custom event.

    Or use that if you don't know what previous syntax means:

     $('.ProductList').on('contentChanged',function(){alert('UL content changed!!!');});
    

提交回复
热议问题