Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
Button to change CSS settings

I want to create a button to change color property from the ball in the game. In CSS text #character, property backgroundcolor.

Here is the code. I really would appreciate if someone could help me.

#character {
  width: 20px;
  height: 20px;
  background-color: red; /* I want to change this property */
  position: absolute;
  top: 100px;
  border-radius: 50%;
}
<body>
  <div id="game">
    <div id="block"></div>
    <div id="hole"></div>
    <div id="character"></div>
  </div>

  <button type="button" onclick="document.getElementById('character').style.color = 'blue'"> Click Me!</button>
</body>

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You are using the wrong style property, instead of using style.color, use style.background

Here is a working example:

#character{ /* Definições da bola */
    width: 20px;
    height: 20px;
    background-color: red; /* I want to change this property */
    position: absolute;
    top: 100px;
    border-radius: 50%;
}
<!DOCTYPE html>
<html>
  <head> <!-- Head do jogo -->

    <meta charset="UTF-8">
    <title>Flappy Bird</title>
    <link rel="stylesheet" href="flappybird_style.css">

</head>

<body> <!-- Corpo do jogo -->

    <div id="game"> <!-- Divs que representam cada parte do jogo -->
        <div id="block"></div>
        <div id="hole"></div>
        <div id="character"></div>
    </div>
    
    <button type="button" onclick="document.getElementById('character').style.background = 'blue'"> Click Me!</button>

</body>

<script src="script.js"> </script>
</html>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Since initially you are setting the background color of the circle to red, you need to change this property, instead of changing the color property

#character {
  width: 20px;
  height: 20px;
  background-color: red; /* I want to change this property */
  position: absolute;
  top: 100px;
  border-radius: 50%;
}
<div id="game">
  <!-- Divs que representam cada parte do jogo -->
  <div id="block"></div>
  <div id="hole"></div>
  <div id="character"></div>
</div>

<button type="button" onclick="document.getElementById('character').style.backgroundColor = 'blue'"> Click Me!</button>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda