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

178
Vistas
How to fix elem.innerHTML not working more than once

Here Im facing a strange problem. I have a button which when clicked inserts <h1>Hello</h1> to a target element. I found out that the click only works once and doesn't show any errors. Im not able to figure out why its not working.

Here's my code

const addMore = document.querySelector('#addMore');
let parentElem = document.querySelector('#target');
addMore.addEventListener('click', function() {
  parentElem.innerHTML += `
        <h1>hello</h1>
        `
})
<div class="col-md-12" id="target">
  <div class="row">
    <div class="col-md-2 mb-3">
      <div class="form-group">
        <label for="price" class="form-label small">Price</label>
        <div class="input-group">
          <span class="input-group-text">₹</span>
          <input type="number" name="price" id="price" class="form-control" placeholder="100">
        </div>
      </div>
    </div>
    <div class="col-md-2 mb-3 d-flex align-items-end">
      <button type="button" class="btn btn-primary" id="addMore">+ Add More</button>
    </div>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza
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