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

259
Vistas
Can you get the value of an HTML element that equals zero in JavaScript?

I am trying to get access to an HTML element that (currently) equals zero in HTML.

HTML element in a Django template:

{% for post in page_obj.object_list %}
            <div class = "individual_posts">
                <h6 id = "post_itself_{{ post.id }}" class="post_itself">{{ post.post }}</h6>
                <h6 id="likes_{{ post.id }}" class = "post_elements">{{ post.likes }}<button class="like_button">&#x1F44D;</button></h6>
{% endfor %}

The default for {{ post.likes }} is zero, but I am trying to get access to the HTML element, so that I can increase the value.

JavaScript:

document.addEventListener('DOMContentLoaded', function(){
    const likeButtons = document.querySelectorAll('.like_button');
    for (const l_button of likeButtons){
        l_button.addEventListener('click', (event) => like(event.target.id));
    }
  });

function like(id){
       let likes = document.querySelector(`#likes_${id}`);
       console.log(likes)
       console.log(likes.value);
       let likeNum = likes +=1;
}

From the first console.log, I get null. From the second console.log, I get undefined.
Does anyone know how to access the value of this id?

about 4 years ago · Santiago Trujillo
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