9

i looking for a way to preview the text while im typing in a textarea in jquery

exactly what u are using for Stackoverflow ,

Mac Taylor
  • 4,832
  • 13
  • 49
  • 70

1 Answers1

21
<script>
  $(document).ready(function () {
    $('#someTextBox').keyup(function(){
      $('#target').html($(this).val());
    });
  });
</script>

<textarea id="someTextBox"></textarea>
<div id="target"></div>

As you type text in the <textarea>, the text should be duplicated in the HTML of the <div>.

MalcolmOcean
  • 2,675
  • 2
  • 28
  • 36
Justin Niessner
  • 236,029
  • 38
  • 403
  • 530
  • 4
    +1. You should promote jQuery's shorthand document ready with `$(function(){...});` – David Murdoch Apr 21 '10 at 15:54
  • 3
    @Justin, either use `this.value` or `$(this).val()`. – Gabriele Petrioli Apr 21 '10 at 15:59
  • @David Murdoch, I am not so sure about that. Its an old debate. It is much more readable even if its a bit longer way – adardesign Apr 21 '10 at 16:04
  • eh, usually document ready is at the very top the of the script element/file and I find that readability isn't ever an issue. But if you are burying `$(document).ready(...)` within other code for some odd reason I totally agree with you. – David Murdoch Apr 21 '10 at 16:16
  • hey guys i need to use my php function to show slugged title how can i use php function between jquery codes ? – Mac Taylor Apr 21 '10 at 16:47