I am new to jQuery and so don't mind this question if it sounds stupid but here is something that I am trying to do :
I have 3 functions like:
AddToCart Function which adds item to the shopping cart:
//offer_id is the offer which we are trying to add to cart.
addToCart: function(offer_id)
{
},
RemoveFromCart which removes data from the cart
//target is link clicked and event is the click event.
removeFromCart: function(target, event)
{
},
Get the current state of the cart
//return string which represents current state of cart.
getCartItems: function()
{
}
Now I am trying to do 3 things:
- if there is no
contentin cart andaddToCartis called thansome action, so basically here we need to check the current state of cart and that is obtained by callinggetCartItemsand if it isNulland than ifaddToCartis called than we performsome action - if there is
contentin the cart andaddToCartis called thansome action,so basically here we need to check the current state of cart and that is obtained by callinggetCartItemsand check if it isNullor not and than ifaddToCartis called than we performsome actionif we had some content in the cart. - if there is
contentin the cart andremoveFromCartis calledsome action, so basically here we need to check the current state of cart and that is obtained by callinggetCartItemsand if it is not Null and ifremoveFromCartis called than we performsome action
Pseudocode of what I am trying to do:
if there is no content in cart
and addToCart is called than
$(document).track(
);
if there is content in the cart
and addToCart is called than
$(document).track(
);
if there is content in the cart
and removeFromCart is called
$(document).track(
);
My basic concern is that am complete newbie to jQuery and JavaScript and so am not sure how can I implement if...else logic and how can I call a function using jQuery/JavaScript.
myCartwhich is a basic JS object, and have it created at the start (empty), and add and remove without concern of it the cart exists or has content.