I am using the below Jquery code to add items to cart. My intention is to change the "Add to cart" button once the Ajax call is success. However its not happening. Code is below -
jQuery.post('/cart/add.js', {
quantity: 1,
id: variant_id
}, function(data){
var myelem = document.getElementById('red') ;
if (myelem != null){
document.getElementById('red').id = 'normal';
}
$("span").removeClass("hidden-count");
$(".cart-count").text('1');
$("#AddToCartText").text("Added");
$("#AddToCart").css("color","Green");
});
Currently, the code is adding the item to cart but I am not seeing the intended element manipulations. The jquery to manipulate the elements is correct, because when I remove it from the success callback, and put it just after the AJAX call (without any dependency on AJAX call), in that case the element is getting manipulated.
- I have referred to http://api.jquery.com/jquery.post/ to verify the syntax.
- I have checked "Console" in Developer tools (Chrome), there are no error messages there.
Please let me know, where I am making mistake.