tags:

views:

19

answers:

1

i am using prettify, i am wondering if i can make it work with any code block, not requiring the prettyprint class.

else, how can i attach the class prettyprint dynamically, maybe using jquery. what i want to acheive is similar to stack overflow where code typed in the editor will be "pretty printed" in the preview and output.

i tried

$("#main").delegate("code", "ready", function() {
    // this does not seem to run at all?
    // intending to add the prettyprint class here
});
A: 
$(document).ready(function(){ $('code').addClass('prettyprint'); });
  • $(document).ready(<func>) runs <func> when the DOM is ready.
  • $('code') selects all code tags.
  • .addClass() adds the specified class to any elements it is passed (in this case, all of the code tags).
Amber
but in my case i think i need to use delegate so that as user adds code into the textarea, in the markdown preview the code will be prettified. how can i do that. my code above dont seem to work. if i change the event to hover it works tho ...
jiewmeng