Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter HTML real-time with input tag

How can I can I alter (change, add, whatever) HTML/text real-time using the input tag? Very similar to the preview interface when asking a question on Stack Overflow minus the code encoding. It just has to be simple.

For example,

<input type="text" name="whatever" />
<div id="example"></div>

Whatever text is entered in the above input tag is added to #example in real-time. Something involving innerHTML and JavaScript perhaps?

like image 920
UserIsCorrupt Avatar asked Feb 14 '26 17:02

UserIsCorrupt


1 Answers

You can do this with jQuery

$('input').keyup(function(){
    var a = $(this).val();
    $('#example').text(a); 
});

Example: http://jsfiddle.net/5TnGT/

like image 76
Jason Gennaro Avatar answered Feb 16 '26 06:02

Jason Gennaro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!