Help - Search - Members - Calendar
Full Version: Getting The Value Of An A Tag
Invision Power Services > Community Forums > Community Web Design and Coding
Kennedy_merged
I have some HTML (that I cannot change or remove) and I need to get the value of it (the text that is displayed).

QUOTE
<table width="100%" id="userlinks" cellspacing="6">
<tr>
<td><strong>Logged in as: <a href='http://s11.invisionfree.com/cbox_tests/index.php?showuser=1'>Kennedy</a></strong> ( <a href='http://s11.invisionfree.com/cbox_tests/index.php?act=Login&amp;CODE=03'>Log Out</a>&nbsp;&middot; <b><a href='http://s11.invisionfree.com/cbox_tests/admin.php' target='_blank'>Admin CP</a></b> &middot; <b><a href='http://s11.invisionfree.com/cbox_tests/index.php?act=modcp&amp;forum='>Mod CP</a></b> )</td>
<td align='right'>
<b><a href='http://s11.invisionfree.com/cbox_tests/index.php?act=UserCP&amp;CODE=00' title='Edit my settings, such as signature, avatar and more...'>My Controls</a></b> &middot; <a href='http://s11.invisionfree.com/cbox_tests/index.php?act=Msg&amp;CODE=01'>Inbox (0)</a>
&middot; <a href='http://s11.invisionfree.com/cbox_tests/index.php?act=Search&amp;CODE=getnew'>View New Posts</a> &middot; <a href='java script:buddy_pop();' title='View posts since your last visit, moderator lists and more...'>My Assistant</a></td>
</tr>

</table>



The bold is the `A` tag in question, the italic is the info that I need.
Kennedy_merged
Nevermind, I used a[0].innerHTML. smile.gif
briansol
innerHTML is not cross-browser, nor is it a standard. it seems to work on most modern browsers, but its not reliable.

document.getElementsByTagName("a")[0] is how you want to access it.

more reading: http://slayeroffice.com/articles/innerHTML_alternatives/
Kennedy_merged
I have this so far

QUOTE
function get_username()
{
user_bar = document.getElementById('userlinks');
if( user_bar )
{
username = false;
a = user_bar.getElementsByTagName("A");
for(t=0;t<a.length;t++)
{
username = a[0];
}
alert (username);
iframe = document.getElementsByTagName('iframe');

for (p=0;p<iframe.length;p++)
{

alert(iframe[p]);

if (iframe[p].width == '700' && iframe[p].height == '75' )
{

name = iframe[p].getElementsByTagName( 'input' );

alert( name );

for (y=0;y<name.length;y++)
{
if(name[y].value.match("name") && name[y].className == "frmtb")
{
textbox = name[y];
}
}

textbox.value = username;

alert(textbox);
alert(username);
}

}
}
}


The two bolded lines alert the links `href`.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.