<!DOCTYPE html> <html> <head> <title>Try jQuery Online</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> $(document).ready(function() { $('div.pretty-print-feature').each(function(i, d) { var featureHTML = '<table>'; try { var features = JSON.parse(d.innerHTML).features; for (feature in features) { featureHTML += '<tr>'; featureHTML += '<td class="table_detail w e s"><b>'+feature+'</b></td>'; featureHTML += '<td class="table_detail e s"><b>$ '+features[feature].price.grossprice+'</b> (Total excl. Tax: $ '+features[feature].price.netprice+')</td>'; if (features[feature].promotion_details != undefined) { featureHTML += '<td class="table_detail e s"><table>'; for (var i = 0; i < features[feature].promotion_details.length; i++){ if (features[feature].promotion_details[i].discount_plan != undefined) { featureHTML += '<tr><td><b>promotion name<b></td><td>'+features[feature].promotion_details[i].discount_plan+'</td></tr>'; if (features[feature].promotion_details[i].discount != undefined) { featureHTML += '<tr><td><b>promotion discount<b></td><td><b>$ '+features[feature].promotion_details[i].discount.grossprice+'</b> (Total excl. Tax: $'+features[feature].promotion_details[i].discount.netprice+'</td></tr>'; } if (features[feature].promotion_details[i].promotion_conditions != undefined) { featureHTML += '<tr><td><b>promotion condition<b></td><td><ul>'; for (var j = 0; j < features[feature].promotion_details[i].promotion_conditions.length; j++){ featureHTML += '<li>'+features[feature].promotion_details[i].promotion_conditions[j]+'</li>'; } featureHTML += '<ul></td></tr>'; } } } featureHTML +='</table></td>'; } featureHTML += '</tr>'; } featureHTML += '</table>' console.log(featureHTML); $(".tableresult").html(featureHTML); } catch (e) { console.log(e); } }); }); </script> <style> .selected { color:red; } .highlight { background:yellow; } table, th, td { border: 1px solid black; } </style> </head> <body> <div class="pretty-print-feature" style="display:none">{"features":{"TRANSIT_COVER":{"price":{"tax":"0.61","tax_rate":0.1,"currency":"AUD","grossprice":"6.67","netprice":"6.06"},"extra_service_code":"EXTCVD","promotion_details":[{"discount_plan":"33%","discount":{"tax":"0.30","tax_rate":0.1,"currency":"AUD","grossprice":"3.33","netprice":"3.03"},"promotion_conditions":["ItemInclusionsExclusionsCondition"]}],"startrack":false,"attributes":{"cover_min":1,"cover_max":5000,"amount":500.00,"article_value_threshold":500.0},"bundled":false,"is_shipment_feature":false}}}</div> <div class="tableresult"> </div> </body> </html>
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more