Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript function onhover in <div>

I have got this code in HTML:

<div id="choice" onHover="npcRoll()">
    <p>Choose your weapon!</p>
    <button id="rock" onClick="choose(1)">Rock</button>
    <button id="paper" onClick="choose(2)">Paper</button>
    <button id="scissors" onClick="choose(3)">Scissors</button>
    <p>You chose <span id="userChoice"></span>!</p>
</div>

And here is my JavaScript code for it:

// Random
var random = function(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
};  

// NPC
var npc;
function npcRoll(){
    npc = random(1, 3);
}

And here is the CSS code:

#choice {
    margin: 0 auto;
    border: 2px solid gray;
    width: 350px;
}

The idea was to make roll NPC number every time the user hovers over the <div> but it doesn't work. Can you help me with it?

like image 841
Kyrbi Avatar asked Mar 18 '13 20:03

Kyrbi


1 Answers

There is no onHover event, use onmouseover:

<div id="choice" onmouseover="npcRoll()">
like image 55
VisioN Avatar answered Oct 08 '22 16:10

VisioN