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

230
Views
How to show hidden json with button?

I have two buttons SHOW and HIDE. When show is clicked numbers will appear (which are json files, each json file contain only one number 1, 2, 3..) when HIDE is clicked first number(json) in a row dissapear. For example we clicked SHOW button 3 times and got this: 1 2 3 and then clicked HIDE once then we got: 2 3 shown. My problem is when HIDE is clicked I want to save that deleted number by showing it in my div where id="nome". After another clicking on button HIDE another hidden number is shown and old is deleted from div.

var pageCounter = 1;
var pageCounterr = 1;
var animalContainer = document.getElementById("animal-info");
var animalContainerr = document.getElementById("nome");
var btn = document.getElementById("btn");
var btnn = document.getElementById("btnn");

btn.addEventListener("click", function() {

  var ourRequest = new XMLHttpRequest();
  ourRequest.open('GET', 'http://10.0.9.243/animals-' + pageCounter + '.json');
  ourRequest.onload = function() {
    var ourData = JSON.parse(ourRequest.responseText);
    renderHTML(ourData);
  };
  ourRequest.send();
  pageCounter++;
});

function renderHTML(data) {
  var htmlString = document.createElement("div");
  for (i = 0; i < data.length; i++) {
    let pText = document.createTextNode(data[i].name);
    let pElement = document.createElement("p");
    pElement.append(pText);
    htmlString.append(pElement);
    htmlString.classList.add('containers') // new Line added
  }
  animalContainer.append(htmlString);

}

btnn.addEventListener("click", function() {
  let containers = document.getElementsByClassName('containers');
  if (containers.length > 0) {
    containers[0].remove();
  }
});
<button id="btn">SHOW</button>
<button id="btnn">HIDE</button>
<h2>Numbers:</h2>
<div id="animal-info"></div>

<h2>Hidden number is:</h2>
<div id="nome"></div>

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!