rippy
rippy

Reputation: 195

Is there any way to use onmouseover and onmousedown together?

This code works fine for onMouseOver and onMouseOut events, but it doesn't work for onMouseDown. Here is the code that I wrote in HTML5 and JavaScript. Let me know the mistakes that I am make. Please help. Thanks in advance.

<!DOCTYPE html>
<html>
 <head>
     <title>Zero cross</title>
 </head>

<body>
    <script>
        function changecolor(vals) {
            document.getElementById(vals).style.color = "red";
            document.getElementById(vals).innerHTML = "Click to select";
        }

        function changeagain(vals) {
            document.getElementById(vals).style.color = "#000000";
            if (vals == 'cross') {
                document.getElementById(vals).innerHTML = "X";
            } else {
                document.getElementById(vals).innerHTML = "0";
            }
        }

        function selection(vals) {
            document.getElementById(vals).style.color = "yellow";
            if (vals == 'cross') {
                document.getElementById(vals).innerHTML = "X";
            } else {
                document.getElementById(vals).innerHTML = "0";
            }
        }
    </script>

    <div align="center">
        <p id="cross" onmouseover="changecolor('cross');" onmouseout="changeagain('cross');" onmousedown="selection();">
            X
        </p>
        <p id="zero" onmouseover="changecolor('zero');" onmouseout="changeagain('zero');" onmousedown="selection();">
            0
        </p>

    </div>

</body>

Upvotes: 0

Views: 698

Answers (1)

Khanh TO
Khanh TO

Reputation: 48972

you forgot to send the Id

<p id="cross" onmouseover="changecolor('cross');" onmouseout="changeagain('cross');" onmousedown="selection('cross');">
            X
        </p>
        <p id="zero" onmouseover="changecolor('zero');" onmouseout="changeagain('zero');" onmousedown="selection('zero');">
            0
        </p>

Check onmousedown="selection('zero');" and onmousedown="selection('cross');"

Upvotes: 4

Related Questions