简体   繁体   中英

How to get the text content inside a Text Area with Jquery using its class name

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.

You Can Use:

$(selector).text() ie

$('.x').text();

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> 

check below code for this:

$(document).ready(function () {
  alert($('.x:first').html());
})

Hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM