tags:

views:

45

answers:

2

i have an text area like this one which i write in it now now i want when onchange the textarea content appear in a pre i used

<textarea id="content" onchange="perview();"></textarea>


function perview() {
var code = $("textarea#content").val();
$('#code-preview').html(code);
}   

i think every thing is ok

<pre id="code-preview"></pre> 

but when using highlighter on the pre its not working like that

<pre id="code-preview" class="brush: php;"></pre>

the SyntaxHighlighter version 2.1.364 (October 15 2009)

A: 

instead of using onchange="" try using

$(document).ready(function(){
     $('textarea#content').change(function(){
          var code = $(this).val();
          $('#code-preview').html(code);
     });
});

you may also want to try a few other things such as .blur() instad of .change().

also remove the ; from your class. that should read:

<pre id="code-preview" class="brush:php"></pre>

I hope this has been helpful.

JSD
what's with the negative vote? if it's about the class fix, so you know it's actually part of a plugin that he's using called syntax highlighter which requires you used class="brush:php" or brush:js and so on and so on.here's the examples:http://www.lastengine.com/syntax-highlighter-wordpress-plugin/#usage
JSD
+1  A: 

have you tried,

function perview() {
   var code = $("textarea#content").val();
    $('#code-preview').html(code);
    SyntaxHighlighter.all() // <--- calling this again...
} 

that is if we are using same highligher. if that works, please try not inline events.. ;) cheers...

Reigel