Parse Javascript variable value to JSON object

49 views Asked by At

I need help printing javascript variable into a JSON object with its value which it has fetched. Please check my code:

     <script type="text/javascript" data-ampdevmode="">
    var postid = document.querySelector('.status-publish').getAttribute('id').replace("post-", "");
    </script>
    <script type="text/javascript" data-ampdevmode="">
    console.log(postid);
    </script>
    
 <amp-state id="wpp-json-amp">   

    <script type="application/json" id="wpp-json">
        {
            "ID": postid
        }
        </script>
    </amp-state>

Here "postid" will get the id of WordPress post.

Also its not printing the inside content of <script type="application/json" id="wpp-json"> on amp page.. can anyone help me with this?

0

There are 0 answers