How to get prettyprint to work on dynamically generated dom element
javascript, pretty-print
Solution
As far as I can tell your code seems correct.
1) include pretty print ( not the run_xxx) version
2) call prettyPrint() any time your Dom is updated
However your script that includes prettyPrint is missing a closing ", so maybe it's just a typo your problem :)
Problem
I'm using prettyprint plugin as syntax highlighter, it work fine when page loads but when i add new elements dynamically it doesn't work! I tried using `prettyPrint()` to invoke it after loading the new contents but it didn't work! i also followed the instructions on the plugin website by wrapping `prettyPrint()` with a function but it didn't work neither! any help would be much appreciated. i installed the plugin like this: ``` <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script> ``` my code is: ``` function showCode(e){ (e.preventDefault) ? e.preventDefault() : e.returnValue = false; var parent = document.createElement('div'), pre = document.createElement('pre'), code = document.createElement('code'), elm = (e.currentTarget) ? e.currentTarget : e.srcElement, src = elm.getAttribute('href'), id = elm.getElementsByTagName('img')[0].getAttribute('src').replace(/images\/(.+?)\.png/g, "$1"); parent.id = "codeZoom"; pre.className = "prettyprint linenums lang-" + id; var xhr = (window.XMLHttpRequest) ? new window.XMLHttpRequest() : new activeXObject("Microsoft.XMLHTTP"); xhr.open('get', src, true); xhr.send(); xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { var text = document.createTextNode(xhr.responseText); code.appendChild(text); pre.appendChild(code); parent.appendChild(pre); document.getElementsByTagName('body')[0].appendChild(parent); center(parent); prettyPrint(); } } } ``` currently i'm getting the error message prettyPrint is not defined.