Skip to content

Instantly share code, notes, and snippets.

@gonaumov
Last active March 5, 2020 11:48
Show Gist options
  • Save gonaumov/d30a7e1bc1761fb4af56dcd440b87502 to your computer and use it in GitHub Desktop.
Save gonaumov/d30a7e1bc1761fb4af56dcd440b87502 to your computer and use it in GitHub Desktop.
<!--
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