rooboy09
11-27-2009, 11:53 PM
Hello, from an "almost-newbie".
I have been using inline event-handlers so that when a user hovers over a menu link, text appears in a box describing the link.
// javascript in head of menu.html
function textDisplay(desc){
document.getElementById('descriptionBox').innerHTML = desc;
}
// menu.html
<ul>
<li><a href="index.html" onmouseover="textDisplay('Home page')">Home</a></li>
<li><a href="about.html" onmouseover="textDisplay('About me')">About</a></li>
</ul>
<div id="descriptionBox"></div>
Now I'm making my markup more semantic by referencing the links with an external javascript, but how do I pass textDisplay() an argument telling it which link it is?
// external menu.js
navLinks = document.getElementById("menu").getElementsByTagName("li");
navLinks.onmouseover = textDisplay; // THIS IS THE POINT I NEED HELP WITH
function textDisplay(???){
document.getElementById("descriptionBox").innerHTML = ???;
}
// menu.html with no event handlers in xhtml
<ul id="menu">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="home.html">Home</a></li>
</ul>
<div id="descriptionBox"></div>
I am a self taught newbie, hope this isn't wasting anyone's time!
Many thanks
I have been using inline event-handlers so that when a user hovers over a menu link, text appears in a box describing the link.
// javascript in head of menu.html
function textDisplay(desc){
document.getElementById('descriptionBox').innerHTML = desc;
}
// menu.html
<ul>
<li><a href="index.html" onmouseover="textDisplay('Home page')">Home</a></li>
<li><a href="about.html" onmouseover="textDisplay('About me')">About</a></li>
</ul>
<div id="descriptionBox"></div>
Now I'm making my markup more semantic by referencing the links with an external javascript, but how do I pass textDisplay() an argument telling it which link it is?
// external menu.js
navLinks = document.getElementById("menu").getElementsByTagName("li");
navLinks.onmouseover = textDisplay; // THIS IS THE POINT I NEED HELP WITH
function textDisplay(???){
document.getElementById("descriptionBox").innerHTML = ???;
}
// menu.html with no event handlers in xhtml
<ul id="menu">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="home.html">Home</a></li>
</ul>
<div id="descriptionBox"></div>
I am a self taught newbie, hope this isn't wasting anyone's time!
Many thanks