I have the following code, which filters/ displays certain divs according to their corresponding number. For example clicking the 'onestar' link will only display divs with 'onestar' in the class name. This works fine when the page is first loaded. But suppose I request some new markup via post in JQuery, the link filters stop working. For some reason, the filters stop working when the new markup is retrieved by JQuery Ajax. Thanks
This is the code that does the js filtering
$('#filtero-stars li a').click(function(){
$('#filtero-stars li').removeClass('active');
$(this).parent().addClass('active');
var colorClass = '.' + $(this).attr('class');
if(colorClass=='.all') {
$('#nothing_found').remove();
$wall.children('.invis').toggleClass('invis').fadeIn(500);
} else {
if ($wall.children(colorClass).length == 0) {
$('#demo .wrap').append(getNothingFound()).fadeIn(500);
setTimeout(function(){$('#nothing_found').show();},600);
} else $('#nothing_found').remove();
$wall.children().not(colorClass).not('.invis').toggleClass('invis').fadeOut(500);
$wall.children(colorClass+'.invis').toggleClass('invis').fadeIn(500);
}
});
this is the HTML markup for the filter
<ul class="star-rating" id="filter0-stars">
<li><a href="#onestar" class="onestar">
<div class="one"></div>
<span>1 Star</span></a></li>
<li><a href="#twostar" class="twostar">
<div class="two"></div>
<span>2 Stars</span></a></li>
<li><a href="#threestar" class="threestar">
<div class="three"></div>
<span>3 Stars</span></a></li>
<li><a href="#fourstar" class="fourstar">
<div class="four"></div>
<span>4 Stars</span></a></li>
<li><a href="#fivestar" class="fivestar">
<div class="five"></div>
<span>5 Stars</span></a></li>
<li><a class="all" href="#">Show all</a></li>
</ul>
this is the content which is filtered
<div id="demo">
<div class="box threestar">
<div class="box twostar">
<div class="box onestar">
</div>
This is the code that retrieves the new mark up, after which the filters don't work
$.post('get-offers.php', $("#offerForm").serialize(), function(data) {
$('#demo').html(data);