onclick event does not work on Chrome!

Asked

Viewed 474 times

1

I’m not managing to perform a transition exercise. I have the img One lamp’s out and one’s lit and one’s broken! Until accesses I could, but when it is pa, to break the code does not work!

Here is source code:

<!DOCTYPE  html>
<html>
<head>
    <title>teste javascript </title>
    <meta charset="UTF-8"/>
    <script>
    function acendeLampada(){
    document.getElementById("Luz").src = "_imagens/Lampada-acesa.jpg ";
    }
    function apagaLampada() {
    document.getElementById("Luz").src = " _imagens/Lampada-apagada.jpg ";
    }
    function quebraLampada() {
    }
    document.getElementById("Luz").src = "_imagens/lampada-quebrada.jpg ";
    </script>
</head>
<body>
<h1> Acenda a lâmpada</h1>
<img src="_imagens/Lampada-apagada.jpg" id="Luz" onmousemove="acendeLampada()" onmouseout=" apagaLampada()" onclick="quebra-Lampada()"/>
</body>
</html> 
  • 1

    Where is the onclick event?

  • 1

    I’m still learning how to ask the questions.

  • Quiet. It’s a bit complicated even rs.

  • Welcome Wellington Samuel, if any answer solved your problem mark it as accepted, see how and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

2 answers

3


There are basically 2 errors in your code:

1. Action outside the function:

function quebraLampada() {
    }
    document.getElementById("Luz").src = "_imagens/lampada-quebrada.jpg ";

Correct:

function quebraLampada() {
    document.getElementById("Luz").src = "_imagens/lampada-quebrada.jpg ";
}

2. Function missing from tag <img>:

onclick="quebra-Lampada()"

Correct:

onclick="quebraLampada()"

OTHER PROBLEMS:

Although it might work, it’s not a good practice leave these blanks at the beginning or end of sequences as:

" _imagens/Lampada-apagada.jpg "; RUIM
"_imagens/Lampada-apagada.jpg"; BOM
  • DVD Valew mano vc is fuck also guy I had not noticed so obvious neh I put out the brackets then only put there lamp broke when clicked man thank you

  • @Wellingtonsamuel Thanks man! Don’t forget to mark the answer so don’t get "loose" around! ;)

2

From what I noticed, its function broke Supported with opening and closing the {} in the wrong position!

WRONG

function quebraLampada() {
}

document.getElementById("Luz").src = "_imagens/lampada-quebrada.jpg ";

CERTAIN

function quebraLampada() {
 document.getElementById("Luz").src = "_imagens/lampada-quebrada.jpg ";
}
  • 1

    very much obliged to you guy you are fucking guy! vlw really worked out

Browser other questions tagged

You are not signed in. Login or sign up in order to post.