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.
<script> const desc = $('meta[name=description]').attr("content").toString(); var schema = { "@context": "http://www.schema.org", "@type": "LocalBusiness", "name": "BizName", "telephone": "+1234567890", "description": desc, .... } var script = document.createElement('script'); script.type = "application/ld+json"; script.text = JSON.stringify(schema);
document.querySelector('body').appendChild(script);</script>
Related Topics
How to Show Alternate Image If Source Image Is Not Found? (Onerror Working in Ie But Not in Mozilla)
How to Load an Entire HTML Document into a Document Fragment in Internet Explorer
Pass Mouse Events Through Absolutely-Positioned Element
How to Show a Hidden Div When a Select Option Is Selected
For Loop Through Array Only Shows Last Value
Execjs::Runtimeerror on Windows Trying to Follow Rubytutorial
Ways to Circumvent the Same-Origin Policy
How to Merge Properties of Two JavaScript Objects Dynamically
What Is Innerhtml on Input Elements
Changing Nav-Bar Color After Scrolling
Select All Elements With a "Data-Xxx" Attribute Without Using Jquery
Canvas2D Todataurl() Different Output on Different Browser
How to Include CSS and Jquery in My Wordpress Plugin
Does JavaScript Have Something Like Ruby'S Method_Missing Feature