I have a jQuery script that runs on document ready and tries to get some values for configuration. I want to store this values inside JSON.
I’ve done this:
<div id="settings" style="display: none">{"name": "value"}</div>
However, this is not search engine friendly.
Is there another way to embed JSON inside html and then pulling with jQuery?
Thanks.
Yes, you can create a
<script>element with a custom type attribute and an ID. You can use the ID to get that element and retrieve the text content.Of course, you could just insert the JSON in with your other script, and assign it to a variable.
However, there’s no guarantee that search engines will index the contents of a script element.
Instead you could just create a hidden element of some kind, with the JSON as its text content.