Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
¿Puede obtener el valor de un elemento HTML que es igual a cero en JavaScript?

Estoy tratando de obtener acceso a un elemento HTML que (actualmente) es igual a cero en HTML.

Elemento HTML en una plantilla de Django:

 {% 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 %}

El valor predeterminado para {{ post.likes }} es cero, pero estoy tratando de obtener acceso al elemento HTML para poder aumentar el valor.

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; }

Desde el primer archivo console.log, obtengo null . Desde el segundo console.log, obtengo undefined .
¿Alguien sabe cómo acceder al valor de este id?

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!