Hi, I have the below script (found on the net) to do some swap content function. Everything works great except when I set the current css to the first 'button' it goes to the last one instead. I want the current css color to be set on the first bullet but it goes to the last bullet. please help. thx.
Code:function hideswapcontent () { var divs=document.getElementById('swapcontent').getElementsByTagName('div'); for (j=0; j<divs.length; j++) { var rE = new RegExp("(^|\\s)" + 'story' + "(\\s|$)"); if (rE.test(divs[j].className)) { divs[j].style.display="none"; } var buttons=document.getElementById('buttons').getElementsByTagName('a'); for (k=0; k<buttons.length; k++) { // loop throught the buttons and remove the 'current' class var li=buttons[k].parentNode; li.className=li.className.replace(new RegExp("current"+"\\b"), ""); }}} function swapcontent(first) { var buttons=document.getElementById('buttons').getElementsByTagName('a'); for (i=0; i<buttons.length; i++) { buttons[i].onclick=function() { hideswapcontent(); var thestory=(this.href).split("#",2)[1]; document.getElementById(thestory).style.display="block"; if(thestory=="location"){ var currCenter = map.getCenter(); google.maps.event.trigger(map, 'resize'); map.setCenter(currCenter); } this.parentNode.className+=" current"; // set the 'current' class to the clicked button return false; }} if (first) { var firstone=document.getElementById('swapcontent').firstChild; if (firstone.nodeType != 1) {firstone = firstone.nextSibling;} firstone.style.display="block"; var firstbutton=document.getElementById('buttons').lastChild; if (firstbutton.nodeType != 1) {firstbutton = firstbutton.previousSibling;} firstbutton.className+=" current"; // set the 'current' class to the first button }}


Reply With Quote
Bookmarks