473,396 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.getElementById(a_strTableId);

for(var i = 0; i < table.rows.length; i++) {
for(var j = 0; j < table.rows[i].cells.length; j++) {
a = table.rows[i].cells[j].getElementsByTagName("A")
alert(a.href);
if (strCurrentpath = a.href) {
a[i].className = 'yellow';
a[i].parentNode.className = 'space_on_bottom';
}
}
}

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
getElementsByTagName like I am attempting?

Any help is greatly appreciated.

Have a nice night,
Ryan

Aug 3 '05 #1
3 4747
<ry*********@gmail.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.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.getElementById(a_strTableId);

for(var i = 0; i < table.rows.length; i++) {
for(var j = 0; j < table.rows[i].cells.length; j++) {
a = table.rows[i].cells[j].getElementsByTagName("A")
alert(a.href);
if (strCurrentpath = a.href) {
a[i].className = 'yellow';
a[i].parentNode.className = 'space_on_bottom';
}
}
}

What I am expecting is to obtain the hrefs of the anchors inside of the
given tabletable = document.getElementById('a_strTableId');
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.length; i++)
for(var j = 0; j < table.rows[i].cells.length; j++)
{
a = table.rows[i].cells[j].getElementsByTagName("A")

alert(a[0].href);

if (strCurrentpath == a[0].href)
{
a[i].className = 'yellow';
a[i].parentNode.className = 'space_on_bottom';
}
}

--
Stephen Chalmers
547265617375726520627572696564206174204F2E532E2072 65663A205451323437393134

Aug 4 '05 #2
ry*********@gmail.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.getElementById(a_strTableId);

for(var i = 0; i < table.rows.length; i++) {
for(var j = 0; j < table.rows[i].cells.length; j++) {
a = table.rows[i].cells[j].getElementsByTagName("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.className = 'space_on_bottom';
}
}
}

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
getElementsByTagName like I am attempting?


var table = document.getElementById(a_strTableId);
var a = table.getElementsByTagName('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.className = 'space_on_bottom';
}
}

[...]

--
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
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...
2
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...
5
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...
2
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...
3
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...
3
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...
1
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...
1
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...
8
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.