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

269
Vistas
Can't trigger event more than once (Jquery, HTML)

I'm trying to do a little script that allows a user to automatically creates a div once the tab button is pressed and the focus is on the y input.

That div is a duplicated of the previous div.

I don't know what I'm missing, but it only triggers with the first element, and not the dinamically created ones.

This is my code:

<script type="text/javascript">
        $(document).ready(function() {
            createElement();
            $('.y').on('keydown', function(event) {
                if (event.repeat) {
                    return;
                }
                if(event.key === "Tab") {
                    createElement();
                }
                $(this).unbind('keydown');
            });
        });
        function createElement() {
            $('body').append('<div class="clue-div"><div class="clue-name"><label>Pista:</label><select id="clue-name"></select></div><div class="clue-coords"><label>X:</label><input type="number" class="x"><label>Y:</label><input type="number" class="y"></div></div>');
            $.get('/get_element_names.php', function(data) {
                $.each(data, function(index, val) {
                    $("select:last").append('<option value="'+val.name+'">'+val.name+'</option>');
                });
            });
        }
    </script>

Can you guys help me with this? Thank you in advance.

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