We help IT Professionals succeed at work.

Jquery not working when Ajax loads new products

Aaron Roessler
on
49 Views
Last Modified: 2020-04-03
I have a very simple click(function applied to the Add To Cart button below all products that will open the sidebar quick cart view. but that does not work when i use the Category Filter on my products page... when I click a category checkbox (Lips) the products are sorted but my jQuery click function does not work anymore.

Script works fine on this page with no filter: https://allgood.flywheelsites.com/shop/
Soon as I choose a shop by category box the Ajax filter loads the correct products. Example "Lips"

But then my jQuery code does not work... why is that?

jQuery('.product_type_simple').click(function(){
      console.log("add to cart btn clicked");
window.setTimeout(function(){jQuery(".elementor-menu-cart__container").addClass("elementor-menu-cart--shown");
}, 1500);
});
Comment
Watch Question

Aaron RoesslerWeb Developer

Author

Commented:
yay... figured it out.  

used this..

      jQuery(document).on('click','.product_type_simple', function () {  
      console.log("add to cart btn clicked");
window.setTimeout(function(){jQuery(".elementor-menu-cart__container").addClass("elementor-menu-cart--shown");
}, 1500);
});
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Aaron RoesslerWeb Developer

Author

Commented:
This is a GREAT understandable explanation. which also helped me figure out another issue i had. THANK YOU!

I needed this similar scenario but not using the on click.. but for (on"mouseover"). I tried and it did not work as expected but finally got it working!!
I only need this to fire on my woo shop page, so i checked for specific body class:
if (jQuery('body').hasClass('post-type-archive-product')) {
	jQuery(document).on('mouseover','.jet-woo-products__item', function () {  
		jQuery('.jet-woo-products__item').removeClass('jet-woo-thumb-with-effect');
});	}

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
You are welcome

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.