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

214
Vistas
innerHTML is not working inside a function

I'm a beginner in Javascript programming. innerHTML method is not working in a function to update content of a HTML element.

My JS code is :

$(':button').on("click", function() {
  // reference clicked button via: $(this)
  var buttonElementId = $(this).attr('id');
  var sliceId = buttonElementId.charAt(buttonElementId.length - 1);
  bringData(sliceId);

})

function bringData(id) {
  var a = localStorage.getItem("Blogs")
  var b = JSON.parse(a)
  console.log(b[id].blogHeader)
  document.getElementById("foo").innerHTML = b[id].blogHeader
}

Buttons and element which has id of "foo" are at different HTML pages. I want to update content of that element after clicking any button from other page, but it is not working. The content still remains same. What is my mistake ?

Note : If I use innerHTML property out of a function, it works and content is changing.

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