john fernado
john fernado

Reputation: 127

why is event.button not working properly with mousedown event in Chrome?

Here's a picture of the error:

enter image description here

I'm trying to get the event.button to do something when someone left clicks on a image, but the event.button is not working for me. I don't know why I'm getting this error. Is it saying that my event parameter is undefined in my Javascript code, or is it saying that buttons is undefined? I don't understand, I could use some help with this question. I set event.buttons equal to x and if x == 1 which means if someone left clicks one of images then something happens.

Here is the javascript code:

function dontShowDots(event) {
    var x = event.buttons;
    if (x == 1) {
        arrayDots[0].style.display = "none";
        arrayDots[1].style.display = "none";
    }
}

Here's my html code:

<!DOCTYPE html>
<html>
    <head>
        <title>Title of the document</title>
        <link rel="stylesheet" href="style.css">
    </head>

    <body>
        <div id="container">
            <div class="empty-squares"><img src="images/greenDot.png" height="50px" width="60px"></div>
            <div class="empty-squares"><img src="images/greenDot.png" height="50px" width="60px"></div>
            <div id="square1"><img src="images/white_pawn.png" onclick="showDots()" height="75px" width="75px"></div>
        </div>
        
        <div id="container1">
            <div class="empty-squares"><img src="images/greenDot.png" height="50px" width="50px"></div>
            <div class="empty-squares"><img src="images/greenDot.png" height="50px" width="50px"></div>   
            <div id="square2"><img src="images/white_pawn.png" onmousedown="dontShowDots()" onclick="showDots2()" height="75px" width="75px"></div>
        </div>           
            
        
        <script src="interactive.js"></script>
    </body>

</html>

css code:

.empty-squares img {
    display: none;
}

Upvotes: 0

Views: 416

Answers (2)

Wang Liang
Wang Liang

Reputation: 4434

onmousedown="dontShowDots(event)" 

One can access the current event through window.event. Just using event is implicitly accessing window.event.

Upvotes: 1

Bogdan Filimon
Bogdan Filimon

Reputation: 101

Try:

onmousedown="dontShowDots(event)" 

Upvotes: 2

Related Questions