Pawan
Pawan

Reputation: 32331

How to get the value table td text value in this case

Please see this following fiddle .

https://jsfiddle.net/86gef8qa/2/

How can i get the value FTSE in this case ??

I have tried using

$("tbody tr").each(function(){
    console.log($(this).find("td a").text());
});

could you please let me know how can i read the value

Upvotes: 0

Views: 31

Answers (2)

nbermudezs
nbermudezs

Reputation: 2844

Well, is that how you have the HTML in your real app? You are missing the <table></table> wrap on the tbody, Chrome might allow that but it isn't valid HTML.

On the other hand, you have multiple td with a inside of it. So $(this).find("td a") is capturing multiple elements. And text needs to be called in a single one.

So I suggest to add a class to the column (td) that will hold FTSE, let's call it ftse, and change the query to $(this).find("td.ftse > a"). If you want to get all the text of all the <a>'s you might want to iterate over then inside the each you already have, like this:

$("tbody tr").each(function(){
    $(this).find("td > a").each(function() {
        console.log($(this).text());
    });
});

Feel free to check the modified fiddle here

Upvotes: 1

charlietfl
charlietfl

Reputation: 171700

Use eq() to target the cell index:

$("tbody tr").each(function(){
    console.log($(this).find("td:eq(3) a").text());
});

DEMO

Upvotes: 1

Related Questions