Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get TD value using jQuery.?

Tags:

jquery

I am trying to get value of td using jquery like this.

$("#id").find(".class").attr('value'); 
//or
$("#id").find(".class").val();

both returns empty string although it has a value. note* i'm trying get value of dynamically created element. thanks in advance.

like image 353
Ejaz Karim Avatar asked Nov 30 '22 13:11

Ejaz Karim


2 Answers

Just write

$("#id .class").text();

Or to get the HTML use,

$("#id .class").html();
like image 87
Arvind Bhardwaj Avatar answered Dec 27 '22 18:12

Arvind Bhardwaj


The val() function is primarily used to get the values of form elements such as input, select and textarea. You need text() or html() function to get the contents of td.

To get text

textOfTd = $("#id").find(".class").text();

To get Html

textOfTd = $("#id").find(".class").html();
like image 24
Adil Avatar answered Dec 27 '22 19:12

Adil