Search code examples
javascriptcssprettify

Using Prettify on dynamically-generated code


I'm using Prettify for syntax highlighting, but it doesn't work on dynamically generated code.

I have a form that when submitted generates code and displays it (without refreshing) in <div id="output></div>, but prettify doesn't work on this code, is there any workaround?

Many thanks!


Solution

  • Make sure you recall Prettify once the new code is loaded.

    You will need to add a handler to the 'Submit' event. I don't know if you are using a framework or raw JS, so I can't give a code example.