Reputation: 189
How can I retrieve table header data within <a>
tag such as Name
using jQuery or JavaScript?
My html is:
<table style="width:100%">
<tr>
<th><a href="www.a.com">Name<a></th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
Upvotes: 0
Views: 119
Reputation: 2422
I'm not sure whether I get your question right, but shouldn't the following work?
$('th').find('a').each(function(){console.log($(this).text())});
-> Result in your case Name
<table style="width:100%">
<tr>
<th><a href="www.a.com">Name<a></th>
<th><a href="www.a1.com">Name1<a></th>
<th><a href="www.a2.com">Name2<a></th>
<th><a href="www.a3.com">Name3<a></th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
-> Result is:
Name
Name1
Name2
Name3
Upvotes: 1
Reputation: 959
You can use $("table tr th a").text();
or $("table tr th a").html();
Upvotes: 0
Reputation: 1262
I would give your link tag and ID, then use:
document.getElementByID(linkID).href;
Upvotes: 0