Reputation: 673
I have this table structure.
<table id = "table1">
<thead>
<tr id = "header_row">
<th> <a id = "a1">ABC</a> </th>
<th> <a id = "a2">DEF</a> </th>
<th> <a id = "a3">GHI</a> </th>
<th> <a id = "a4">JKL</a> </th>
</tr>
</thead>
<tr>.....data filling up the table.....</tr>
<tr>.............</tr>
.
.
</table>
So from this table, I want to fetch the value "a2", Can you please tell me how to do this? Thanks!
EDIT: There are many other <a>
<table>
tags on the page, so if there is any way to extract using the id?
Upvotes: 0
Views: 722
Reputation: 2248
To fetch the value of the #a2
you can simply do:
Plain JavaScript:
document.getElementById('a2').innerHtml;
jQuery:
$('#a2').text();
So from this table, I want to fetch the value "a2"
makes me think that you're using the same id
s for different tables in the same page and you want to retrieve data from a specific one, aren't you?
This situation is wrong, id
s MUST be unique in your whole page so if this is your case consider using classes
Upvotes: 1
Reputation: 68363
So from this table, I want to fetch the value "a2"
You mean fetch the id of second column in the header row?
Try this
$("#header_row th a:eq(1)").attr("id")
If you simply wants to fetch ABC of a know a
based on its id
then
$("#a2").html(); //or text()
Upvotes: 2