Possible duplicate:
jquery loading problem
I am dynamically loading content into a div using the jQuery load () function. In the callback, I call SyntaxHighlighter.all () to print the syntax of the pre-block that just loaded in the div.
The problem is that the content is loading OK, but the syntax is not highlighted. However, when I hardcode the pre-block into a div, so I donβt load into the DOM via the jquery load () function, the syntax will be highlighted as it should.
So, I assume that SyntaxHighlighter.all () only works with preview blocks that are in the html source, which can be viewed using the source of the view page, and not on the actual content in the DOM?
Any idea how I can make it work?
javascript to load and highlight:
<script type="text/javascript"> $.ajaxSetup ({ cache: false }); $(document).ready(function() { var tree = $("#tree li"); var contentContainer = $("#contentContainer"); var content = $("#content"); SyntaxHighlighter.config.clipboardSwf = 'syntaxhighlighter_2.0.320/scripts/clipboard.swf'; SyntaxHighlighter.all(); // Treeview $("#tree").treeview({ persist: "location", collapsed: true }); tree.click(function() { if ($(this).hasClass("file")) { tree.removeClass("selected"); $(this).addClass("selected"); content.load("content/"+this.id+".html", function() { contentContainer.effect("highlight"); SyntaxHighlighter.all(); }); } }); }); </script>
div content:
<div id="content"> <pre class="brush: java;"> class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!");
external file that is loaded using jQuery.load ():
Hello World <pre class="brush: java;"> class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!");
Yours faithfully
source share