473,756 Members | 6,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Anchor collection inside html table

Hi all, I hope somebody here can help me, I am attempting to obtain a
reference to the anchors inside of a table. Here is what I have:

table = document.getEle mentById(a_strT ableId);

for(var i = 0; i < table.rows.leng th; i++) {
for(var j = 0; j < table.rows[i].cells.length; j++) {
a = table.rows[i].cells[j].getElementsByT agName("A")
alert(a.href);
if (strCurrentpath = a.href) {
a[i].className = 'yellow';
a[i].parentNode.cla ssName = 'space_on_botto m';
}
}
}

What I am expecting is to obtain the hrefs of the anchors inside of the
given table. Is there a better way to achieve this? Can I not
getElementsByTa gName like I am attempting?

Any help is greatly appreciated.

Have a nice night,
Ryan

Aug 3 '05 #1
3 4768
<ry*********@gm ail.com> wrote in message news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Hi all, I hope somebody here can help me, I am attempting to obtain a
reference to the anchors inside of a table. Here is what I have:

table = document.getEle mentById(a_strT ableId);

for(var i = 0; i < table.rows.leng th; i++) {
for(var j = 0; j < table.rows[i].cells.length; j++) {
a = table.rows[i].cells[j].getElementsByT agName("A")
alert(a.href);
if (strCurrentpath = a.href) {
a[i].className = 'yellow';
a[i].parentNode.cla ssName = 'space_on_botto m';
}
}
}

What I am expecting is to obtain the hrefs of the anchors inside of the
given tabletable = document.getEle mentById('a_str TableId');
alert(a.href); // you need to specify a subscript here if (strCurrentpath = a.href) {
a[i].className = 'yellow';


You have used assignment '=' instead of equalty '=='

This will work, but still relies on each cell containing only one link:

for(var i = 0; i < table.rows.leng th; i++)
for(var j = 0; j < table.rows[i].cells.length; j++)
{
a = table.rows[i].cells[j].getElementsByT agName("A")

alert(a[0].href);

if (strCurrentpath == a[0].href)
{
a[i].className = 'yellow';
a[i].parentNode.cla ssName = 'space_on_botto m';
}
}

--
Stephen Chalmers
547265617375726 520627572696564 206174204F2E532 E207265663A2054 51323437393134

Aug 4 '05 #2
ry*********@gma il.com wrote:
Hi all, I hope somebody here can help me, I am attempting to obtain a
reference to the anchors inside of a table. Here is what I have:

table = document.getEle mentById(a_strT ableId);

for(var i = 0; i < table.rows.leng th; i++) {
for(var j = 0; j < table.rows[i].cells.length; j++) {
a = table.rows[i].cells[j].getElementsByT agName("A")
alert(a.href);
a is a collection and does not have an href attribute.
if (strCurrentpath = a.href) {
a[i].className = 'yellow';
a[i].parentNode.cla ssName = 'space_on_botto m';
}
}
}

What I am expecting is to obtain the hrefs of the anchors inside of the
given table. Is there a better way to achieve this? Can I not
getElementsByTa gName like I am attempting?


var table = document.getEle mentById(a_strT ableId);
var a = table.getElemen tsByTagName('a' );

'a' will be a collection of the A elements inside the table. Presumably
'strCurrentpath ' is a string passed to the function and represents some
URI. Fixing the '=' issue and using a appropriately:

for (var i=0, j=a.length; i<j; i++ ){
if ( strCurrentpath == a[i].href ) {
a[i].className = 'yellow';
a[i].parentNode.cla ssName = 'space_on_botto m';
}
}

[...]

--
Rob
Aug 4 '05 #3
Oh my gosh, I made such silly mistakes . . . thank you both for showing
me the error of my ways. Just when you start to think you're a web
developer :)

Have a great day!
Ryan

Aug 4 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1629
by: Anna | last post by:
Hello all. I hope this is the right group to ask my question. I have an HTML page that contains an SVG file in an object. Inside an SVG file I want to add a link to link to some anchor on the including HTML page. I tried to do it, but it doesn't seem to work. Here is my example: test.svg: <?xml version="1.0" standalone="no"?>
2
16575
by: splish | last post by:
Hello, I have the following problem: An Iframe exists inside a page (that has content exceeding the height, therefore scrollbars kick in) - normal stuff. When I want to use anchor references inside the Iframe the parent page is affected also, in that it jumps to the top of the iframe, as though there were an anchor at that point.
5
25854
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the function...if that makes sense. Here's what I mean... I have a javascript array set up like so: <script language="javascript" TYPE="text/JavaScript"> //custom object constructor
2
4171
by: skipc | last post by:
I posted a recent message regarding navigating a table using arrow keys. I've got the code for the navigation working. My table contains rows of links (anchors). I can get to a specific link using the code for capturing a key. However, once I get to the link, I can focus(), for example... but what I really want is to activate the "hover" styles. I can fake the hover effect using javascript, but how do I do this and still allow the...
3
4080
by: axlq | last post by:
I wrote the function below to get the vertical scroll position of an anchor. That is, a URL of the form http://www.example.com/mypage.html#anchorname should scroll to the point on the page that has an anchor <a name="anchorname">...</a>). Doing this in Javascript is necessary in the presence of a dynamic HTML page having some hidden blocks. DHTML messes up the scroll position in Opera and Mozilla (but not IE) so I'm trying to fix it...
3
2381
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central panel. The central panel is intended to display the main content of the cv: when an anchor is selected from the header then the detail is supposed to appear. The javascript is supposed to select the appropriate section 'onclick' and output it....
1
1796
by: baskarpr | last post by:
Could somebody help me ? I believe this might be elementary, but I am not much familiar with HTML .In my page i have two frames. I have a number of anchor tags in right frame. Every anchor tag in left side is associated to some text and one anchor as header in right frame. When I click in left anchor tag it should focus the associated content in the right frame. Below is main HTML page partly. <frameset cols="40%,60%"> <frame...
1
7737
by: praveenb000 | last post by:
Hi every one, I designed a web page, having horizontal menu using UL and LI tags; I need to be set rollover effect for a menu items. whenever user hover on a menu item, the entire item(including anchor tag text) has to change to another color, but since iam using anchor tag in LI tag, the text in the menu item is not changing color when i hover on the menu item(LI). (but changing color when i hover on the anchor tag Text). But i...
8
5138
by: azjudd | last post by:
Thank you in advance for your help on this one. I'm using named anchor tags on a FAQ page with questions listed at the top and answers below; a standard jump-to feature. However, anytime an anchor tag link is used, whether it be a question down to an answer or an answer back to the list of questions, I lose the banner div, a good portion of of my MenuDv disappears, and white space is added to the bottom of my page. You can see my FAQ page...
0
9431
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10014
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7226
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6514
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5119
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2647
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.