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

215
Views
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
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!