I'm trying to leave checkboxes checked when ajax returns the content from server but I don't know what is unchecking them or replacing the dom content (reseting them)...
}).done(function(data) {
if ($( '#search' ).is(':visible'))
$( '#search' ).hide();
if ($(this).is(':checkbox')) {
var new_content = $(data).find( '#scroll-to-list' );
$( '#scroll-to-list' ).replaceWith( new_content );
}
else {
var new_content = $(data).find( '#search-filters, #scroll-to-list' );
$( '#results' ).html( new_content );
}
$( 'html, body' ).animate({
scrollTop: $( '#scroll-to-list' ).offset().top
}, 1000);
});
A search button triggers the on click event and prints the new divs in the dom, hiding the #search div (and the radio buttons, but one of them is still checked). Now appears the #search-filters div and checkboxes, when I check one of them the ajax is called and what prints to the dom is only the second div (containing the search data), but the checkboxes (from #search-filters) are unchecked and I can't figure out what is causing that...
This is the code that handles the checkboxes (before the ajax):
$('body').on('click', '.click, :checkbox, .pag_link', function() {
if ($(this).is(':checkbox')) {
if ($(this).attr('class') == 'filter1' || $('.filter1').is(':checked')) {
if ($('.filter1').is(':checked'))
var type = $(this).val(); // maybe should be an array
else var type = null;
} else var type = null;
if ($(this).attr('class') == 'filter2' || $('.filter2').is(':checked')) {
if ($('.filter2').is(':checked'))
var status = $(this).val(); // maybe should be an array
else var status = null;
} else var status = null;
if ($(this).attr('class') == 'filter3' || $('.filter3').is(':checked')) {
if ($('.filter3').is(':checked'))
var bhk = $(this).val(); // maybe should be an array
else var bhk = null;
} else var bhk = null;
}
else {
var type = status = bhk = null;
}