Hi There;
I am trying to add some onClick functionality to a group of menu items in a template-based site by creating a javascript function that locates the a tag in this group and adds a new attribute.
It's not working :( Could someone please be kind to look at what i've written and tell me what i'm doing wrong?
Header script:
Code:
<script type="text/javascript">
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
function addAtt() {
if ( !document.getElementById ||
!document.createElement ||
!document.getElementsByTagName ) {
return;
}
var primaryDiv = document.getElementById("navlist");
var primarylinks = primaryDiv.getElementsByTagName("a");
for ( var i = 0; i < primarylinks.length; i++ ) {
primarylinks[i].setAttribute("onClick","Effect.Appear('d6')");
}
}
addLoadEvent(addAtt);
</script>
and in the body:
Code:
<div class="secondnav">
<ul class="links" id="navlist">
<li class="first menu-2-1-49">
<a href="#" class="menu-2-1-49">style</a></li>
</ul>
</div>
<div class="secondnav" id="d6" style="display:none">
<ul class="links" id="subnavlist">
<li class="first menu-2-1-49">
<a href="/dave/node/3" class="menu-2-1-49">style</a></li>
</ul>
</div>
thanks