Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  125] [ 2]  / answers: 1 / hits: 37598  / 11 Years ago, wed, july 24, 2013, 12:00:00

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



Below is my code



JS



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

$('.ProductList').live('change', function() {
alert('content is changed now');
});
});


HTML



<ul class='ProductList List Clear'>
call jquery function when content change here.
<li></li>
<li></li>
<li></li>
</ul>


Suggest me some idea so I can solve it.



I am try to call function based on content change because I work on bigcoomerce customization and big commerce not allow me to access ajax function because of the limited access so I need to call function like that.


More From » jquery

 Answers
53

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!!!');});

[#76784] Tuesday, July 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
denver

Total Points: 232
Total Questions: 111
Total Answers: 103

Location: South Korea
Member since Sat, Oct 2, 2021
3 Years ago
;