Solved

firstChild works in ie but not ff

Posted on 2007-11-15
5
639 Views
Last Modified: 2013-11-19
function deactivate_main_menu_item(elmnt)
{
      elmnt.style.backgroundColor = "#C1C1C1";
      elmnt.firstChild.style.color = "black";
}

The above function works fine in ie but not in ff, the td background colour changes but then the href color does not change.
0
Comment
Question by:shaun_hester
  • 3
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 125 total points
ID: 20288954
Show the call and what you are calling it from

If you have whitespace, then that is the fristChild in FF
0
 

Author Comment

by:shaun_hester
ID: 20289003
td onmouseover="activate_main_menu_item(this)" onmouseout="deactivate_main_menu_item(this)">
      <a HREF="default.asp">Home</a>
</td>
0
 

Author Comment

by:shaun_hester
ID: 20289009
ok so i've changed the above line to

<td onmouseover="activate_main_menu_item(this)" onmouseout="deactivate_main_menu_item(this)"><a HREF="default.asp">Home</a></td>

with no spaces and works perfectly.

So my next question is how do i use the td element as the root and find all href nodes?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20289132
Like this:
<table>
<td><a href="#">Test0</a></td>
<td>
<a href="#">Test1</a>
<a href="#">Test2</a>
<a href="#">Test3</a>
</td>
<td>
<a href="#">Testa</a>
<a href="#">Testb</a>
<a href="#">Testc</a>
</td>
</tr>
</table>
<script>
var table = document.getElementsByTagName('table')[0]
var secondCell = table.rows[0].cells[1];
var links = secondCell.getElementsByTagName("a");
alert(links.length+':'+links[2].innerHTML)
</script>

Open in new window

0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 125 total points
ID: 20289151
Or in your case

<script>
function showSiblingLinks(link) {
  var links = link.parentNode.getElementsByTagName("a");
  alert(links.length+':'+links[2].innerHTML)
return false
}
</script>
 
 
<table>
<td><a href="#">Test0</a></td>
<td>
<a href="#">Test1</a>
<a href="#">Test2</a>
<a href="#" onClick="return showSiblingLinks(this)">Test3</a>
</td>
<td>
<a href="#">Testa</a>
<a href="#" onClick="return showSiblingLinks(this)">Testb</a>
<a href="#">Testc</a>
</td>
</tr>
</table>

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
.htaccess css/images no longer loading 4 35
Angular won't showing my array result in HTML 3 24
asp Google Map 2 26
JQuery Syntax... 4 32
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses four methods for overlaying images in a container on a web page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question