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

207
Vistas
Errors using multiple instances of Odometer JS?

Having a bit of trouble getting Odometer JS to work on multiple elements. I am creating 5 elements via Nunjucks macros and am passing a data attribute to Odometer to be processed.

This is what it the Nunjucks macro currently looks like:

{% for item in items | sort(attribute = item.sum) | limit(5) %}

<div class="odometer" data-counterAmount="{{ item.counterAmount }}"></div>
        
{%- endfor -%}

The current jQuery code:

$(".odometer").each(function(){

    let el = $(this);
    let counterAmount = el.attr("data-counterAmount");

    od = new Odometer({
        el: el,
        value: counterAmount,
        // format: 'd',
        animation: 'ease',
        duration: 400,
    });

});

However, I am getting this error:

Uncaught TypeError: this.el.appendChild is not a function
    at a.renderInside (odometer.min.js:2)
    at new a (odometer.min.js:2)
    at HTMLDocument.eval (mine.js:11)
    at e (jquery-3.6.0.min.js:2)
    at t (jquery-3.6.0.min.js:2)

Any clue on how to resolve this? Any tips are very much appreciated, thanks

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

0

You need to use el: el[0]

Because .appendChild is for javascript and not jquery

Demo

$(".odometer").each(function() {

  let el = $(this);
  let counterAmount = el.attr("data-counterAmount");

  od = new Odometer({
    el: el[0],
    value: counterAmount,
    // format: 'd',
    animation: 'ease',
    duration: 400,
  });

});
.odometer {
  font-size: 100px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Odometr includes -->
<link rel="stylesheet" href="http://github.hubspot.com/odometer/themes/odometer-theme-car.css" />
<script src="http://github.hubspot.com/odometer/odometer.js"></script>
<div class="odometer" data-counterAmount="123"></div>
<div class="odometer" data-counterAmount="456"></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