Search code examples
javascriptonclickonmousedownonmouseup

Javascript button click + reveal


I have a big red button and I'm trying to use javascript to perform the following: -

  1. OnMouseDown change image so the button looks depressed
  2. OnMouseUp return to the initial image AND reveal a hidden div

I can get the onMouse Down and onMouseUp image changes part to work.

I can also get the hidden div to reveal by using OnClick

The problem is I can't get it all to work together.

How do I do this?

BTW, I'm sure its obvious, but I'm fairly new to javascript, so I appreciate your help


Solution

  • You can use semicolons to separate multiple script statements in an event:

    <img src="..." alt="..."
      onmousedown="depressed();"
      onmouseup="undepressed(); revealDiv();" />
    

    Also, I believe most browsers support the onclick event:

    <img src="..." alt="..."
      onmousedown="depressed();"
      onmouseup="undepressed();"
      onclick="revealDiv();" />
    

    Since you said you had already figured out each of the 3 parts separately, I just wrote function calls that you can replace with your own code for each step.