Arun Laxman
Arun Laxman

Reputation: 386

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.

Upvotes: 1

Views: 748

Answers (3)

Rohit Mittal
Rohit Mittal

Reputation: 2104

check below code for this:

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

Hope it helps you.

Upvotes: 1

Maheer Ali
Maheer Ali

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

Aayush
Aayush

Reputation: 459

You Can Use:

$(selector).text() i.e

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

Upvotes: 2

Related Questions