Reputation: 386
I have an automatically generated textarea with a class name, say "x". How do I get the text inside the text area given that there will be only one element with the class name "x" in that page.
I have tried the following and can't make it to work.
<textarea class="note-codable" role="textbox" aria-multiline="true" style="height: 390px;">
some content
</textarea>
<script>
$(document).ready(function () {
alert($('.note-codable').val());
alert($('.note-codable').first.val());
alert($('.note-codable').text());
})
also how do i update the same text area? any help is appreciated. thanks in advance.
Upvotes: 1
Views: 748
Reputation: 2104
check below code for this:
$(document).ready(function () {
alert($('.x:first').html());
})
Hope it helps you.
Upvotes: 1
Reputation: 36584
use .val()
. Its working fine
$(document).ready(function () {
console.log(document.querySelector('.note-codable'))
alert($('.note-codable').val());
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea class="note-codable" role="textbox" aria-multiline="true" style="height: 390px;">
some content
</textarea>
Upvotes: 1