Reputation: 57
I have used knockout and got these back from my ModelView template ...
<div class="both">
<td>
<h3 data-bind="text: MyText"> What type of fruit is healthy ?</h3>
<textarea data-bind="attr:{id: Question}" class="my-response" id="1"> this is my text area value </textarea>
</td>
</div>
<div class="both">
<td>
<h3 data-bind="text: MyText"> What type of Veg is healthy ?</h3>
<textarea data-bind="attr:{id: Question}" class="my-response" id="2"> this is my text area value</textarea>
</td>
</div>
I want to get the value of text area and this is not working..
$('.both').each(function() {
alert($('.my-response').val());
});
how can I do that?
Thanks
Upvotes: 0
Views: 312
Reputation: 57
This worked best !
$(function(){
$('.my-response').each(function () {alert($(this).val());});
});
Upvotes: 0
Reputation: 356
you can try this one as well
$(document).ready(function(){
$('.my-response','.both').each(function(){alert($(this).val())});
});
here is the demo
Upvotes: 1
Reputation: 218852
Try this
$(function(){
$('.both').each(function(index,item) {
var v= $(item).find('.my-response').val();
alert(v);
});
});
Working sample : http://jsfiddle.net/2CGWG/3/
Upvotes: 2