Does Schema.Org Markup Work If Markup Is Dynamically Built With JavaScript

Does Schema.org markup work if markup is dynamically built with JavaScript?

Google’s documentation only mentions that they can consume dynamically added structured data if the syntax JSON-LD is used:

Also, Google can read JSON-LD data even when it is dynamically injected into the page's contents, such as by Javascript code or embedded "widgets".

This does not necessarily mean that they can’t read it in case of other syntaxes (like Microdata or RDFa), but at least they don’t document it.

That their testing tool doesn’t read it may or may not mean something (it could be that the tool doesn’t handle this but their internal system does). However, there should be no issue with your actual markup, as you can easily test it yourself by pasting your markup instead of entering your URL.

Schema.org tags for dynamically created search results?

Schema.org is used for search engines. So you have to think about which content a search engine has access to.

Search engines don't necessarily wait for dynamic content (for example content loaded via Ajax, or after user interaction). So all Schema.org markup added to the page after the initial page load may not have the impact you would like.

In your example content is shown after a user enters a search term. A search engine would not get to that content, so adding Schema.org there would be of little use.

Changing schema.org microdata with jQuery?

schema.org, RDF, Microdata, etc. are designed to provide context and information for machines. It provides them a means of accessing the information without having to execute client side code (i.e. JavaScript) and still be able to "understand" what you're talking about.

Even if google was able to understand your client side edits, it's not the only bot out there – others will not pick up these changes.

I'd suggest that you don't use client side code to edit information that's intended to be machine readable. Use it to display content to your users.

If you don't want to mess with your markup, have a look at JSON-LD.

You can easily test your markup with google's Structured Data Testing Tool.

Insert Variable from jQuery Into JSON Schema Markup

Build the schema first then inject it in.