Problem: I have a custom search View that updates with AJAX. When the page loads, I use custom JavaScript to apply custom CSS classes to the parent label of a checkbox if it is checked. When the View is updated with AJAX, the CSS class disappears.
Solution: AJAX updates overwrite not only the results of a View but also the filters. You must apply the CSS class again after the AJAX update by inspecting the checkbox and determining whether or not it is checked.
jQuery(document).ready(function () { // add class to label when input changes jQuery(document).on('click', 'input', function () { if (jQuery(this).is(':checked')) { jQuery(this).parent().addClass('done'); } else { jQuery(this).parent().removeClass('done'); } }); // After ajax load, loop over replaced inputs and re-apply parent element classes if needed jQuery( document ).on( 'js_event_wpv_parametric_search_form_updated', function(event,data) { jQuery('input').each(function (index, item) { if (jQuery(item).is(':checked')) { jQuery(item).parent().addClass('done'); } }); }); });
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 5 replies, has 3 voices.
Last updated by 6 years, 4 months ago.
Assisted by: Christian Cox.