tags:

views:

30

answers:

3

Well I have the live preview of text going using jQuery.

http://jsbin.com/ezuta4

But is there a way where I can put in HTML tags and the HTML won't show but effects the text? Like typing <h1> and the tags turn into headings?

So far:

   $(document).ready(function(){

  $('#text').keypress(function() {
  $('#live').text($(this).val());
  });
}); // end jQuery 
​
+3  A: 

text() will parse anything you enter as literal characters. To allow HTML code, use

  $('#live').html($(this).val());

http://jsbin.com/ezuta4/2

Pekka
Baha! It works!!!!
omnix
+1  A: 

use .html() instead of .text()

Azhar
+1  A: 

Use .html() instead of .text(). This won't escape what you type. Also use .keyup() instead of .keypress(), or else the last character you press won't show until you press something else, the event will happen before the character is rendered.

$('#text').keyup(function() {
    $('#live').html($(this).val());
});

jQuery reference

BrunoLM
Great answer! And I was wondering why it was doing that, THANK YOU!
omnix