Reputation: 3
I've been trying to include a simple javascript to Google Sites. However it doesn't work when pressing the button. I put the code inside an HTML Box. The code works perfectly when tested locally. Here is my code:
<script>
function expandCollapse() {
for (var i=0; i<expandCollapse.arguments.length; i++) {
var element = document.getElementById(expandCollapse.arguments[i]);
element.style.display = (element.style.display == "none") ? "inline" :
"none";
}
}
</script>
<div id="L13a" style="display: inline;">
<a href="javascript: expandCollapse('L13a', 'L13b');">Lent</a>
</div>
<div id="L13b" style="display: none;">
<a href="javascript: expandCollapse('L13a', 'L13b');">Lent</a>
<ul>
<li><strong>tba</strong><br/>
tba
</li>
</ul>
</div>
Is there something I made a stupid mistake?
Upvotes: 0
Views: 170
Reputation: 59292
You should change your function to this:
function expandCollapse() {
for (var i = 0; i < arguments.length; i++) {
var element = document.getElementById(arguments[i]);
element.style.display = (element.style.display == "none") ? "inline" :
"none";
}
}
And you should call it onclick
and not in href
<div id="L13a" style="display: inline;"> <a onclick="expandCollapse('L13a', 'L13b');">Lent</a>
</div>
<div id="L13b" style="display: none;"> <a onclick="expandCollapse('L13a', 'L13b');">HI Lent</a>
Demo:http://jsfiddle.net/TvHdU/
Upvotes: 1