Advertisement
prabapro

JSON inside Data Attribute

Jun 11th, 2021
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //HTML Block
  2. <div style="display: block;" id="ondeposit-event" data-all='{"data":{"status":"WAITING_APPROVAL","payload":{"txRefId":"587457656", "method":"withdrawal","amount":"-14.00 EUR","txAmount":"-14.00","txAmountCy":"EUR","fee":"0.00","pspReferenceId":"","psp": "SafeCharge","accountId":"19f7b136-247c-45c","pspAccount":"Withdraw","success":true,"merchantTxId":"14409134890"}}}' data-success="success">Hello world</div>
  3.  
  4. //GTM Custom JS Varibale to access "Amount" inside the JSON at data-all attribute
  5. function() {
  6.   var all = document.querySelector('#ondeposit-event').getAttribute('data-all');
  7.   all = JSON.parse(all);
  8.   return all.data.payload.amount;
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement