I am trying to apply prettify syntax highlighting to a generated string when the dropdown box is selected. It works fine if the text was placed before-hand, but if it is generated, the text is not highlighted. I've tried calling prettyPrint() function but it still does not work.
$('#db').change(
function(){
query = "";
query = "<pre class=\"prettyprint\" id=\"query\">Insert Into ";
query = query + $('#db').val() + "</pre>";
document.getElementById("pp").innerHTML = query;
prettyPrint();
$.ajax({
url: "functions.php?&f=table",
type: "GET",
data: { db: $('#db').val() }
})
.done(function(result) {
$('#table').html(result);
})
.fail(function() {
alert( "error" );
});
}
);
Here is detailed answer as per documentation
If you load this script then you don't need to call the
prettyPrint()
function it will automatically prettify the content with classprettyprint
But if you load the css and js files separately then you need to call
prettyPrint()
From documentation: and then run the prettyPrint function once your page has finished loading. One way to do this is via the onload handler thus:
DEMO with script included rather than loading separate