Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery: How can we implement if...else logic and call function
    primarykey
    data
    text
    <p>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 :</p> <p>I have 3 functions like:</p> <pre><code>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() { } </code></pre> <p>Now I am trying to do 3 things:</p> <ol> <li>if there is no <code>content</code> in cart and <code>addToCart</code> is called than <code>some action</code>, so basically here we need to check the current state of cart and that is obtained by calling <code>getCartItems</code> and if it is <code>Null</code> and than if <code>addToCart</code> is called than we perform <code>some action</code></li> <li>if there is <code>content</code> in the cart and <code>addToCart</code> is called than <code>some action</code>,so basically here we need to check the current state of cart and that is obtained by calling <code>getCartItems</code> and check if it is <code>Null</code> or not and than if <code>addToCart</code> is called than we perform <code>some action</code> if we had some content in the cart. </li> <li>if there is <code>content</code> in the cart and <code>removeFromCart</code> is called <code>some action</code>, so basically here we need to check the current state of cart and that is obtained by calling <code>getCartItems</code> and if it is not Null and if <code>removeFromCart</code> is called than we perform <code>some action</code></li> </ol> <p>Pseudocode of what I am trying to do: </p> <pre><code> 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( ); </code></pre> <p>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. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload