Solved

firstChild works in ie but not ff

Posted on 2007-11-15
5
634 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
JQuery & CSS Tab Issues 7 26
JavaScript error 1 32
javascript page is not accepting parameters 2 8
Asp.net mvc 5 5 13
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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 …
The viewer will learn how to dynamically set the form action using jQuery.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now