Find jobs - Article directory - Web Hosting - Debt Consolidation - Find jobs

PDA

View Full Version : Advanced javascript


cancer10
Jun 27th 2008, 4:10 am
I have a table. the first table document has a welcome text and the last td has a hyperlink. Is there anyway I can prompt an alert with the text thats on the first td?

Note: there are no IDs/class for the table td in this case.


<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>welcome to my site</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><a href>Clicky</a></td>
</tr>
</table>

sharry
Jun 27th 2008, 4:50 am
oops sorry dint read about the id, ignore my post :)

cancer10
Jun 27th 2008, 4:51 am
Remember, there is no id or class in the table?

sharry
Jun 27th 2008, 4:53 am
yes i posted a code with id, removed it now

koolman
Jun 27th 2008, 6:01 am
You may try

<a href="javascript:void 0" onclick="alertText(this)"> ..</a>
<script type="text/javascript">
function alertText(obj)
{
alert(obj.parentNode.parentNode.parentNode.firstNode.firstNode.innerHTML);
}
</script>

MMJ
Jun 27th 2008, 8:45 am
If its the first td in the whole page use:

alert(document.getElementsByTagName("td")[0].innerHTML);

yankzilla
Jun 27th 2008, 10:56 pm
If its the first td in the whole page use:

alert(document.getElementsByTagName("td")[0].innerHTML);

I agree with him. That's what I was going to suggest, was just fetching the first td in the page. Or if it's not, then find out which one it is, and change the number accordingly.