Solved

firstChild works in ie but not ff

Posted on 2007-11-15
5
638 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

776 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