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

124
Vistas
How to append an Image on two or more dom elements?

I'm finishing up my battleship project and want to add ship images. Before if a player places a ship at a certain coordinate, I just change the color of the divs as an indication of ship being placed. Now I want to place ( append ) images dynamically.

            <div class="gameBoard">
                <div class="grid"></div>
                <div class="grid"></div>
                <div class="grid"></div>
                <div class="grid"></div>
                <div class="grid"></div>
                <div class="grid"></div>
            </div>

The div gameboard above represents my board in the dom. And each divs represent each individual boxs where the players will attack each other. So how can I add one images on lets say to or more divs, so that the image span across those divs.

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

0

Something like this?

function addImage(a,b){
   document.querySelectorAll(".grid")[a].style.background = "url(ship.jpg)"; 
   document.querySelectorAll(".grid")[b].style.background = "url(ship.jpg)";
}
<div class="grid" onclick='addImage(3,4)'></div>
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