1

I'm using javascript to display information of a shop basket. I know how to pull the data and create elements from it, but I need to use one of the variables for an if statement, and am unsure how to.

If this is true: "isPunchOut": false, then I want to target that with jQuery, and do something like $(".button").remove();

How do I do this?

var retailerData = {
"del": {
    "zip": "",
    "city": ""
},
"user": {
    "country": "",
    "phone": "",
    "nbrOrders": 0,
    "isPunchOut": false,
    "name": "",
    "salesPerson": "",
    "customerNo": "",
    "email": ""
},
"order": {
    "shippingSum": 0.0,
    "shippingFormatSum": "\u20AC0",
    "orderno": "0",
    "orderFormatSum": "\u20AC130",
    "voucher": "",
    "orderFormatVat": "\u20AC27,30",
    "currencySymbol": "\u20AC",
    "currency": "EUR",
    "orderVat": 27.3,
    "orderSum": 130.0,
    "items": [{
        "imageURI": "\/imgr\/8c82380c-65f5-43aa-83ad-fae1215b5b39\/70\/70",
        "qtyAvail": 7,
        "price": 130.0,
        "qty": 1,
        "artno": "D630-T7100-GE-REF",
        "vat": 27.3,
        "formatVat": "\u20AC27,30",
        "id": "52307",
        "label": "D630 C2D-T7100/2GB/80GB/DVD/14"/NO COA WLAN",
        "category": "Computers - Notebooks",
        "formatPrice": "\u20AC130",
        "manufacturer": "Dell"
    }]
  }
 }
2

3 Answers 3

1

You can take a look at below JS code for reference:

var isPunchOut = retailerData["user"]["isPunchOut"];
if(isPunchOut === false)
    $(".button").remove();
Sign up to request clarification or add additional context in comments.

Comments

0

I would say you should try some code first and put where you get stuck .We not here to write code for your problems.

var retailerData = {
"del": {
    "zip": "",
    "city": ""
},
"user": {
    "country": "",
    "phone": "",
    "nbrOrders": 0,
    "isPunchOut": false,
    "name": "",
    "salesPerson": "",
    "customerNo": "",
    "email": ""
},
"order": {
    "shippingSum": 0.0,
    "shippingFormatSum": "\u20AC0",
    "orderno": "0",
    "orderFormatSum": "\u20AC130",
    "voucher": "",
    "orderFormatVat": "\u20AC27,30",
    "currencySymbol": "\u20AC",
    "currency": "EUR",
    "orderVat": 27.3,
    "orderSum": 130.0,
    "items": [{
        "imageURI": "\/imgr\/8c82380c-65f5-43aa-83ad-fae1215b5b39\/70\/70",
        "qtyAvail": 7,
        "price": 130.0,
        "qty": 1,
        "artno": "D630-T7100-GE-REF",
        "vat": 27.3,
        "formatVat": "\u20AC27,30",
        "id": "52307",
        "label": "D630 C2D-T7100/2GB/80GB/DVD/14"/NO COA WLAN",
        "category": "Computers - Notebooks",
        "formatPrice": "\u20AC130",
        "manufacturer": "Dell"
    }]
  }
 }

if(retailerData.user.isPunchOut){
//your jquery operation
}

Checkjsfiddle

Comments

0

What about?

   if (!retailerData.user.isPunchOut) { 
        $(".button").remove();
   }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.