Dear all,
I’m learning how to use Javascripts and using Prototype framework by following a step by step tutorial from a book. Unfortunately when I stepping through the following code:
<html>
<head>
<title>
Listing 5-3: Hiding or showing boxes using
document.getElementsByClassName()
</title>
<script type="text/javascript" src="/js/prototype.js"></script>
<style type="text/css">
.box {
width : 300px; text-align : center;
background : #f60; color : #fff;
margin : 10px; font-weight : bold;
}
.box h1 { margin : 0; }
</style>
</head>
<body>
<div>
<input type="button" value="Hide All" onclick="hideAll()" />
<input type="button" value="Show All" onclick="showAll()" />
</div>
<div id="box-container">
<div class="box">
<h1>Box 1</h1>
</div>
<div class="box">
<h1>Box 2</h1>
</div>
</div>
<script type="text/javascript">
function hideAll()
{
// find all 'box' elements and hide them
document.getElementsByClassName('box', 'box-container').each(
function(s) {
s.hide();
}
);
}
function showAll()
{
// find all 'box' elements and show them
document.getElementsByClassName('box', 'box-container').each(
function(s) {
s.show();
}
);
}
</script>
</body>
</html>
it fails on the following statement:
document.getElementsByClassName('box', 'box-container').each(
function(s) {
s.hide();
}
);
Firedebugger, which I’m using, complained and saying that:
document.getElementsByClassName(“box”, “box-container”).each is not a function
Anybody can give me a suggestion what the problem might be? The prototype file can be acquired at Prototype website download (I cannot post a link since this is my first post).
Regards,
ethereal1m