javascript - How to get prettyprint to work on dynamically generated dom element -


i'm using prettyprint plugin syntax highlighter, work fine when page loads when add new elements dynamically doesn't work! tried using prettyprint() invoke after loading new contents didn't work! followed instructions on plugin website wrapping prettyprint() function didn't work neither! appreciated. installed plugin 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 error message prettyprint not defined.

as far can tell code seems correct.

1) include pretty print ( not run_xxx) version

2) call prettyprint() time dom updated

however script includes prettyprint missing closing ", maybe it's typo problem :)


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -