jQuery load() can not work with syntaxhighlighter

132 views Asked by At

I use syntaxhighlighter in my page and it works well.

<pre id="code" class="brush:js">
some code here
</pre>

But it doesn't work when I save to a html file then use jquery load function to load them.

$(function(){
  $("#test").load("test.html");
});

Everything is displayed well except the code scope. Could some one tell me why? Thx!

3

There are 3 answers

0
S.Pols On

Change #test into #code:

$(function(){
  $("#code").load("test.html");
});
0
vernak2539 On

You will probably have to run this code to initialize the syntax highlighter after you have dynamically loaded your code:

SyntaxHighlighter.all()

This could probably be done by the following:

$(function(){
  $("#code").load("test.html", function() {
    SyntaxHighlighter.all();
  });
});
1
Apichai J On

Try this:

SyntaxHighlighter.highlight();