I”m trying to get td values of tr.. but unfortunately it”s not working.. may be there is something wrong

My html looks like

abc value here

My jquery code is

jQuery(“.dname”).find(“tr td:eq(1)”).val();What”s wrong in this ?

*

jQuery find() method returns the descendants of the selected element. You are already selecting the with a class of dname and then trying to find a descendant which is also a .

https://api.jquery.com/find/

The following should work:

jQuery(“.dname”).find(“td:eq(1)”).text();Edit: text() instead of val() as

*

Replace n with child no.

Đang xem: Get html table cell value using jquery

$(“.dname td:nth-child(n)”).text();For e.g. for 2nd child

$(“.dname td:nth-child(2)”).text();

*

*

You”re already filtering on the tr by its class name, so there”s no need to find by tr again.

jQuery(“.dname”).find(“td:eq(1)”).text()Also, you need to .text() to get the contents of a not .val().

Xem thêm: Top 3 Phần Mềm Vẽ Đồ Thị Hàm Số Cho Iphone, Download Phần Mềm Vẽ Đồ Thị

JSBin here.

Hope this helps 🙂

*

Because that is the last child of your you can access it like below,

jQuery(“.dname > td:last-child”).text();

Just wanted to point out that if you want some particular value inserted in the cell then do the following (for example if you need to show the text TEST in the table cell):

$(“.dname td:nth-child(n)”).text(“TEST”);

Thanks for contributing an answer to Stack Overflow!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

Xem thêm: 10 Lý Do Để Yêu Bạn Gái Hơn Tuổi Hơn Bạn (Dành Cho Thanh Thiếu Niên)

To learn more, see our tips on writing great answers.

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged jquery or ask your own question.

How do you remove all the options of a select box and then add one option and select it with jQuery?
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.3.31.38960

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *