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

294
Vistas
Why an ID passed via Class' constructor is dynamic?

In my code, I want to pass a unique ID to the li by using a class. However, whenever I refresh the page, the "data-id" attribute is always changing. So the ID becomes different every time the page is reloaded.

Is there a way to make it static but not setting a preset ID?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <ul>
        <li id="item">ID check</li>
    </ul>
</div>
<script>
    class IdChecker {
        constructor() {
            this.id = Math.round(Math.random() * 10000);
        }
    }
    let item = document.getElementById('item');
    item.setAttribute('data-id', String(new IdChecker().id))
</script>
</body>
</html>

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