1

I want to make a simple jQuery script which will do the following:

  1. I have HTML-code with <p> tag and <textarea> for user to type in.
  2. User types text in <textarea> -> jQuery inserts it in <p> (class="youtyped") tag in HTML-code.

HTML-code:

<p class="youtyped"></p>

<textarea>Please type your text here</textarea>

Example of use: User typed "Hello" in textarea, HTML-code will look like:

<p class="youtyped">Hello</p>

Thanks in advance :)

3 Answers 3

3

Try this,

$('textarea').on('keyup',function(){
    $('p.youtyped').text(this.value);
});

$('textarea').on('keyup',function(){
    $('p.youtyped').text(this.value);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="youtyped"></p>

<textarea>Please type your text here</textarea>

And if you want the value on Enter key then try,

$('textarea').on('keyup',function(e){
    if(e.keyCode==13)
       $('p.youtyped').text(this.value);
});

$('textarea').on('keyup',function(e){
    if(e.keyCode==13)
       $('p.youtyped').text(this.value);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="youtyped"></p>

<textarea>Please type your text here</textarea>

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

$('textarea').keyup(function(){
   $('p.youtyped').html($(this).val());
});

1 Comment

You might want to describe what this code is doing.
0

Try this :

$('textarea').on('keyup',function(){
    $('p.youtyped').text($(this).val());
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.