A
ampeloso
Hello,
I have been Reading the DOM Scripting book by FriendsofEd and have a
question.
He separates the the OnClick event from the href by putting it in a js
file that gets loaded when the page gets loaded. He uses the ID
property,BUT he never actually calls the function:
The Markup:
<ul id="imagegallery">
<li>
<a href="images/fireworks.jpg" title="A fireworks
display">Fireworks</a>
</li>
<li>
<a href="images/rose.jpg" title="A red, red rose">Rose</a>
</li>
<li>
<a href="images/bigben.jpg" title="The famous clock">Big Ben</a>
</li>
</ul>
The Function:
function prepareGallery() {
if (!document.getElementsByTagName) return false;
if (!document.getElementById) return false;
if (!document.getElementById("imagegallery")) return false;
var gallery = document.getElementById("imagegallery");
var links = gallery.getElementsByTagName("a");
for ( var i=0; i < links.length; i++) {
links.onclick = function() {
return showPic(this);
}
links.onkeypress = links.onclick;
}
}
How does the function get called, in particular the onclick event,when
the Markup doesnt call the function.Shouldnt the function sit there
unless its called?
Thanks
Mike
I have been Reading the DOM Scripting book by FriendsofEd and have a
question.
He separates the the OnClick event from the href by putting it in a js
file that gets loaded when the page gets loaded. He uses the ID
property,BUT he never actually calls the function:
The Markup:
<ul id="imagegallery">
<li>
<a href="images/fireworks.jpg" title="A fireworks
display">Fireworks</a>
</li>
</li>Coffee</a>
<li>
<a href="images/rose.jpg" title="A red, red rose">Rose</a>
</li>
<li>
<a href="images/bigben.jpg" title="The famous clock">Big Ben</a>
</li>
</ul>
The Function:
function prepareGallery() {
if (!document.getElementsByTagName) return false;
if (!document.getElementById) return false;
if (!document.getElementById("imagegallery")) return false;
var gallery = document.getElementById("imagegallery");
var links = gallery.getElementsByTagName("a");
for ( var i=0; i < links.length; i++) {
links.onclick = function() {
return showPic(this);
}
links.onkeypress = links.onclick;
}
}
How does the function get called, in particular the onclick event,when
the Markup doesnt call the function.Shouldnt the function sit there
unless its called?
Thanks
Mike