0

CONTEXT

I'm using a a Wordpress plugin (Search & Filter Pro) to filter posts by category and load results via Ajax. Since I have several categories-of-categories (e.g. authors, topics, etc.), I added the code below to make the each super-category behave as an accordion:

 jQuery(function($) {
   $('li h4').on("click", function(){
     console.log('hello!')

     //Expand or collapse this panel
     $(this).next().slideToggle('slow');

   });
 });

PROBLEM

On initial load, this works perfectly, as intended. However, as soon as I click a category and the filtered results show up in the content box, the accordion no longer works and even my console.log fails. None of the classes change after the results have loaded.

QUESTION

Is there any way the Ajax loading could be disabling the ability to use jQuery to target elements as in the code above?

Sekoul
  • 1,361
  • 2
  • 14
  • 30
  • probably because you replace the elements and you did not rebind the events to the new ones. – epascarello Feb 18 '16 at 02:46
  • @epascarello - spot on, I had to use ``` $('li').on("click", 'h4', function(){}``` instead. Thanks for your help! – Sekoul Feb 18 '16 at 13:58

0 Answers0