user2645731
user2645731

Reputation: 23

How to show typed in text as individual div's in a textarea

When I append multiple div and there one textarea, when I Enter text in textarea then text show individual div.

When I type "demo" show demo in one div, then another text enter in textarea like "Example" show second div.

Html

<textarea class="speechttxt" rows="3" cols="4" style="height: 75px;width: 267px; background: inherit; border: 1px solid #999; white-space: pre-wrap; resize: none; margin-bottom: 6px; padding-right: 0;"></textarea>

Javascript

var speech = '<div id="speechID" class="SpeechBubble"><div  class="txtspeech" id="lbl' + (c++) + '"></div></div>';
$('#video_container').append(speech);
$('.speechttxt').keyup(function () {
  var txt = $(this).val();
  $('.txtspeech').html(txt);
});

Its working, but when I append second div then text enter in textarea show in second div.

Upvotes: 0

Views: 131

Answers (1)

Eduardo Molteni
Eduardo Molteni

Reputation: 39413

The second div changes because both divs have the txtspeech class, so this line $('.txtspeech').html(txt) targets both divs.

It's not clear in the sample when are you creating the second div.

Upvotes: 1

Related Questions