function setAccordionJsonLdScript() { var accordion = $("ul.accordion"); if (accordion.length == 0) { return false; } let jsonLdList = []; const ACC_HEADER_SELECTOR = ".accordion-header"; const ACC_BODY_SELECTOR= ".accordion-body"; const SEO_SCHEME_ENABLED= "seo-schema-enabled"; accordion.each(function () { if ($(this).hasClass(SEO_SCHEME_ENABLED)) { $(this).find("li.accordion-item").each(function () { var _this = $(this); const question = trimSpace(_this.find(ACC_HEADER_SELECTOR).text()); const answer = trimSpace(_this.find(ACC_BODY_SELECTOR).html()); jsonLdList.push({ "@type": "Question", "name": question, "acceptedAnswer": { "@type": "Answer", "text": answer } }); }); } }); var scriptElement = document.createElement("script"); scriptElement.type = "application/ld+json"; scriptElement.text = JSON.stringify({ "@context": "https://schema.org", "@type": "FAQPage", "mainEntity": jsonLdList }); $("head").append(scriptElement); } function trimSpace(ldText) { if (ldText) { return ldText.replace(/^\s+|\s+$/gm,""); } } $(document).ready(function () { setAccordionJsonLdScript(); });