10

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
  • 5,020
  • 14
  • 50
  • 73

1 Answers1

22
<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,807
  • 2
  • 29
  • 38
Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
  • 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