Skip to content

Instantly share code, notes, and snippets.

@devdarren7
Last active July 16, 2019 08:19
Show Gist options
  • Select an option

  • Save devdarren7/9bde9623c1a9dae1f72f59df3ea24d7d to your computer and use it in GitHub Desktop.

Select an option

Save devdarren7/9bde9623c1a9dae1f72f59df3ea24d7d to your computer and use it in GitHub Desktop.
Deon add multiple ajax
$(document).ready(function(){
$( ".product" ).each(function(index) {
// hi ---> .product is the class name that represents the product element.
var title = $(this).find('a.title-5').html();
// I have above said we are now looking inside the current product div before looking in the next one
// this represents the current product div the loop is in / on. we then use jquery .find() to look for elements inside this div and then .html() grabs the content
// Add to cart code here.
$.post('/cart/add.js', {
quantity: 1,
id: 794864229,
properties: {
'title': title
}
// i've used my variable of title to set an additional property as an example
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment