javascript - Call JSON.stringify on all pre elements -
i'm trying json.stringify json text in <pre> elements in document specified class, , use google-code-prettify add syntax colouring. since don't know javascript or jquery i'm struggling - far have following:
<body onload="prettyprint()"> ... <pre class="prettyprint lang-js">{...}</pre> ... </body> <script> $('[class="prettyprint lang-js"]').next().text("test"); // call json.stringify()? </script> the pretty-printing works, don't know how call json.stringify or select correct elements.
more specifically, want <pre> elements in document "prettyprint lang-js" class, i'd replace text content results of calling json.stringify on text, , call
google-code-prettify `prettyprint()' syntax colour it.
you can use class selector select element class name. try this.
$('.prettyprint.lang-js').each(function(){ var $this = $(this); $this.text(json.stringify($this.text())); }); //now can call prettyprint prettyprint();
Comments
Post a Comment