Reputation: 507
I want to make a simple jQuery script which will do the following:
<p>
tag and <textarea>
for user to type 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 :)
Upvotes: 1
Views: 443
Reputation: 28513
Try this :
$('textarea').on('keyup',function(){
$('p.youtyped').text($(this).val());
});
Upvotes: 0
Reputation: 40639
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>
Upvotes: 3
Reputation: 5071
Try this
$('textarea').keyup(function(){
$('p.youtyped').html($(this).val());
});
Upvotes: 0