Markus
Markus

Reputation: 2062

Onmousedown javascript not triggered

I've tried to add a hover class to my html element with the following code:

.block {
  height: 50px;
  width: 200px;
  background: yellow;
}

.shadow {
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="block"
     onmouseover="$(this).addClass('shadow');"
     onmousedown="$(this).toggleClass('shadow');"></div>

The class will be added on mouseover but it won't be removed onmousedown.
Why?

Upvotes: 2

Views: 115

Answers (1)

Ramin
Ramin

Reputation: 134

Your code is correct. Check this link:

https://www.w3schools.com/code/tryit.asp?filename=FWXV3Y8JXYTI

Note: onmosedown means when the mouse button is pressed! It's different from mouseout.

Upvotes: 2

Related Questions