Reputation: 91
JavaScript noob here. I'm working on a website and I'm trying to change the z-index of a set of frames using buttons. I can't quite get it to work.
So far this is what I have.
function changeZIndex(i,id) {
document.getElementById(id).style.zIndex=i;
}
And in the body
<A HREF="#" onclick='changeZIndex(1,'aboutus')'><IMG NAME="one" SRC="button1.bmp"></A>
<A HREF="#" onclick='changeZIndex(1,'contactus')'><IMG NAME="two" SRC="button2.bmp"></A>
Yeah, I realize this is probably the stupidest question ever and the answer is really obvious. This is my first time writing JavaScript though, so please go easy on me! :3
Upvotes: 9
Views: 18752
Reputation: 3620
look at your quotes,
then if you change zindex for 'aboutus' to 1, don't forget to change zindex for 'contactus' to 0.
otherwise if you change zindex for 'contactus' to 1, don't forget to change zindex for 'aboutus' to 0.
<A HREF="#" onclick="changeZIndex(1,'aboutus');changeZIndex(0,'contactus');"><IMG NAME="one" SRC="button1.bmp"></A>
<A HREF="#" onclick="changeZIndex(1,'contactus');changeZIndex(0,'aboutus');"><IMG NAME="two" SRC="button2.bmp"></A>
Upvotes: 2
Reputation: 1111
Make sure your quotes are escaped correctly. try:
<a href="#" onclick="changeZIndex(1,'aboutus')"><img name="one" src="button1.bmp"></a>
<a href="#" onclick="changeZIndex(1,'contactus')"><img name="two" src="button2.bmp"></a>
note the double quotes around the onclick
Upvotes: 5
Reputation: 225044
Your quotation marks are wrong - look at the syntax highlighting:
<A HREF="#" onclick='changeZIndex(1,'aboutus')'><IMG NAME="one" SRC="button1.bmp"></A>
<A HREF="#" onclick='changeZIndex(1,'contactus')'><IMG NAME="two" SRC="button2.bmp"></A>
This is how you could do it:
<A HREF="#" onclick="changeZIndex(1,'aboutus')"><IMG NAME="one" SRC="button1.bmp"></A>
<A HREF="#" onclick="changeZIndex(1,'contactus')"><IMG NAME="two" SRC="button2.bmp"></A>
Upvotes: 3