I have 2 buttons (1 submit and 1 reset). I want to trigger the following events: onmousedown,onmouseup,onmouseover and onmouseout. I tested my code but it is not working :/. Would you mind helping me to fix it? HTML:
<div class="buttonwrap">
<div id="eventlisten1">
<input type="submit" value="Submit" name="submit" />
</div>
<div class="eventlisten2">
<input type="reset" value="Reset" name="reset" />
</div>
</div>
Javascript:
function mDown(obj) {
obj.value = "Submitted!"
}
function mUp(obj) {
obj.value = "Thank you!"
}
function mOver(obj) {
obj.style.backgroundColor = "blue";
}
function mOut(obj) {
obj.style.backgroundColor = "yellow";
}
function eListeners() {
var eventlisten1 = document.getElementByClassName('eventlisten1');
var eventlisten2 = document.getElementByClassName('eventlisten2');
eventlisten1.addEventListener('mousedown', mDown, false);
eventlisten1.addEventListener('mouseup', mUp, false);
eventlisten2.addEventListener('mouseover', mOver, false);
eventlisten2.addEventListener('mouseout', mOut, false);
}
window.onload = eListeners();
CSS (for some styling):
.buttonwrap {
position:absolute;
z-index:0;
width:200px;
background:#ccc;
}
input[type=submit] {
padding:10px;
margin:10px 0px 0px -1px;
width:90px;
background-color:#00ff00;
float:left;
border-radius:5px;
}
input[type=reset] {
padding:10px;
margin:10px 0px 0px 15px;
width:90px;
background-color:red;
float:left;
border-radius:5px;
}
Here is a fiddle of it: http://jsfiddle.net/mf2xD/2/ I will rep those nice people who help me out :) Thank you!
addEventListenerinstead of adding the events in html