0

When Text Enter in Textarea then show text in DIV.but Condition is that,i append mutiple DIV then type text in Textare.then show text only one DIV not Other DIV.

My Code :

<button data-bind="adds">ADD</button>
     <div data-bind="foreach: items">
                <div class="SpeechBubble" id="speechID" data-bind="attr: { class: 'SpeechBubble' }">
                <div class="pointer bottom " id="pointer"></div>
                <div class="txtspeech"></div>
            </div>

        </div>

var SpeechBubble = function () {
                this.items = ko.observableArray();
                this.adds = function (item) {
                    this.items.push(item);
                }
            }
            ko.applyBindings(new SpeechBubble());



$('.speechttxt').keyup(function () {
    var txt = $(this).val();
    $('.txtspeech').html(txt);
});

2 Answers2

4

Your code is working your probably need to put it document.ready so that when the script for binding event is execute the element you are looking for is added to DOM and include jQuery

Live Demo

$('.speechttxt').keyup(function () {
    var txt = $(this).val();
    $('.txtspeech').html(txt);
});

You can add jQuery using script tag.

<script src="http://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"></script>    

<script  type="text/javascript">
    document.ready(function(){
        $('.speechttxt').keyup(function () {
            var txt = $(this).val();
            $('.txtspeech').html(txt);
        });
    });
</script>
Community
  • 1
  • 1
Adil
  • 146,340
  • 25
  • 209
  • 204
0

add the class 'txtspeech' to div you want to display the text

Sobin Augustine
  • 3,639
  • 2
  • 25
  • 43