Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Z-Index onclick

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

like image 400
Sean Avatar asked May 21 '11 03:05

Sean


2 Answers

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

like image 160
pthurlow Avatar answered Sep 22 '22 09:09

pthurlow


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>
like image 45
Ry- Avatar answered Sep 21 '22 09:09

Ry-