I am looking to reference some JSON variables on page load. Based on a value being true/false, append a class to an html element.
Can't getting this to work, would appreciate some help - being new to jquery and all.
// html
<form id="add_form">
<script type="application/json" data-type="product"
{"product_options": [
{"sku": "ABC123", "price": "$10", "in_stock": true, "can_order": true, "option1": "Small"},
{"sku": "DEF456", "price": "$20", "in_stock": false, "can_order": false, "option1": "Medium"}], "id": 31, "name": "Some Shirt style"}
</script>...</form>
I'd like to iterate through the elements of the .size_options class and add a class to the li element based on the "in_stock" value in the JSON; i.e. if the value is true, add a class.
// parse JSON data
var obj = JSON.parse($("#add_form script[type='application/JSON']").html());
$(".size_options li").each() {
some code
});
I'd appreciate any help here.
product_optionselement with each.size_options lielement and use.addClass(...)