Jump to content

Collapsing menu in Javascript

- - - - -

  • Please log in to reply
No replies to this topic

#1
DarkLordoftheMonkeys

DarkLordoftheMonkeys

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
I'm doing a web site for one of my college classes, and I created a neat script for the main menu. Each menu item has a plus/minus button next to it. When you click the button, a menu appears or disappears below it. It's a pretty simple script. I just thought I might share some of my website, because I'm working really hard on it.


function showHide(button, div){

	var buttonobj = document.getElementById(button);

	var divobj = document.getElementById(div);

	var plusregexp = /.*plus\.gif$/;

	var minusregexp = /.*minus\.gif$/;

	var isPlusButton = buttonobj.src.search(plusregexp);

	var isMinusButton = buttonobj.src.search(minusregexp);

	// show div

	if( isPlusButton == 0 ){

		divobj.style.display = "block";

		buttonobj.src = "minus.gif";

		buttonobj.alt = "-";

	}

	// hide div

	else if( isMinusButton == 0 ){

		divobj.style.display = "none";

		buttonobj.src = "plus.gif";

		buttonobj.alt = "+";

	}

}


Life's too short to be cool. Be a nerd.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users