Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 727197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:32:23+00:00 2026-05-14T06:32:23+00:00

I am new to jQuery and so don’t mind this question if it sounds

  • 0

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:

  1. if there is no content in cart
    and addToCart is called than some action, so basically here we need to check the current state of cart and that is obtained by calling getCartItems and if it is Null and than if addToCart is called than we perform some action
  2. if there is content in the cart
    and addToCart is called than some action,so basically here we need to check the current state of cart and that is obtained by calling getCartItems and check if it is Null or not and than if addToCart is called than we perform some action if we had some content in the cart.
  3. if there is content in the cart
    and removeFromCart is called some action, so basically here we need to check the current state of cart and that is obtained by calling getCartItems and if it is not Null and if removeFromCart is called than we perform some 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:32:24+00:00Added an answer on May 14, 2026 at 6:32 am

    It’s similar to any other programming language.

    if() {
        ..
    }
    else if() {
        ..
    }
    else if() {
        ..
    }
    

    However, since these actions have to be performed when addToCart and removeFromCart are called, a simple solution is to put those conditions inside the functions itself:

    addToCart: function(offer_id) {
        // add to cart is called and cart IS empty
        if(this.getCartItems().length == 0) {
    
        }
        // add to cart is called and cart is NOT empty
        else {
    
        }
    }
    
    removeFromCart: function(target, event) {
        // remove was called and cart has items
        if(this.getCartItems().length > 0) {
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to JQuery so this question might be an obvious one, but I
I'm using Jquery(don't know if that's relevant), here's the regex: var re = new
I'm new to jquery and I kinda don't get around this. So I have
Ok, I am new to JQuery, I have a modal that has a asp:Literal
I'm new to JQuery and don't have a huge background in Javascript, either -
I have some HTML that looks like this: <ul class=faq> <li class=open> <a class=question
I've been trying to use the new jquery-ui, and all but the resizable function
I'm not sure why this isn't working. I don't have any errors, but what
I'm new to jQuery and Javascript. I'm trying to make a button that I
i am beginer in jquery and i don't have experince in jquery but i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.