Web Analytics Made Easy -
StatCounter Problems with GetElementsByTagName in Firefox - CodingForum

Announcement

Collapse
No announcement yet.

Problems with GetElementsByTagName in Firefox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with GetElementsByTagName in Firefox

    I'm using javascript to read links in my navigation bar, compare it to the current page path, and change the style of some TDs if the paths match (i.e. highlight the page you're on). I'm using a combination of GetElementById and GetElementsByTagName, and it works fine in IE but not in Firefox.

    Here's a snippet of the HTML code:
    Code:
    <span id="step1">
        <td><img src="/funnelnav/step_1.gif" width="40" height="50" /></td>
        <td class="paddedtext"><a href="/popandenvironment/index.cfm">Introduction</a></td>
    </span>
    and here's the bulk of the JS code:
    Code:
    for (j=1; j<=6, j++) {
    	var curstep = "step" + j;
    	if (document.getElementById(curstep)) {
    		var target = document.getElementById(curstep).getElementsByTagName("a")[0].href;
    		if (target == curloc) {
    			activecells = document.getElementById(curstep).getElementsByTagName("td");
    			for (x in activecells) {
    				activecells[x].className="active";
    			}
    		}
    	}
    }
    I've tried breaking things out a bit more for testing, such as:
    if (document.getElementById(curstep)) {
    document.write("Current step is " + curstep + "<br>");
    var stepspan = document.getElementById(curstep);
    var linktext = stepspan.getElementsByTagName("a");
    var target = linktext[0].href;
    ...
    }
    and by printing out linktext.length, I can see that it's not finding any of the anchor tags inside the span -- the array length is 0, and the Firefox JavaScript console tells me linktext[0] has no properties.

    If I use document.getElementsByTagName("a") instead, then Firefox will find the links in the entire document, but that's not what I need. Plus, the getElementsByTagName("td") further down in the code won't work either.

    It seems that Firefox won't look inside my span tag for the getElementsByTagName items, even though if I print the value for "stepspan" it returns [object HTMLSpanElement] so I know it's finding it correctly.

    Any ideas? Please let me know if you need more code.
Working...
X