I use the prettyprint plugin as a syntax shortcut, it works fine when the page loads, but when I add new elements dynamically, it does not work! I tried using prettyPrint() to call it after loading the new content, but it will not work! I also followed the instructions on the plugins website, wrapping prettyPrint() with a function, but it didn't work either! Any help is appreciated. I installed the plugin as follows:
<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(); } } }
I am currently getting a prettyPrint error message undefined.
user2202413
source share