Last active
March 5, 2020 11:48
-
-
Save gonaumov/d30a7e1bc1761fb4af56dcd440b87502 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Just an idea. You don't need any event listeners, | |
id's and etc. Try this. If it works for you this | |
is the cleanest solution. | |
--> | |
<div style="display: none;"> | |
[ | |
{"id": 1}, | |
{"id": 2} | |
] | |
</div> | |
<script> | |
(function () { | |
// If data doesn't exist we will | |
// fail silently. | |
try { | |
const data = JSON.parse( | |
document.currentScript.previousElementSibling.textContent | |
); | |
console.log(data); | |
} catch (e) {} | |
})() | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment