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

102
Vistas
I Want a Button that hide the div and restore it

I want to create a button that will hide each ticket and one general button that will restore them all.

this is the Code:

return (
  <ul className="tickets">
    {filteredTickets.map((ticket) => (
      <li key={ticket.id} className="ticket">
        <h5 className="headline">{ticket.headline}</h5>
        <p className="text">{ticket.text}</p>
        <footer>
          <div className="data">
            By {ticket.address} | {new Date(ticket.time).toLocaleString()}
          </div>
        </footer>
      </li>
    ))}
  </ul>
);
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

here is an example of what you want! you have to replace myFunction() for your button and myDIV into your element that you want to hide it!

<button onclick="myFunction()">Click Me</button>

    function myFunction() {
      var x = document.getElementById("myDIV");
      if (x.style.display === "none") {
        x.style.display = "block";
      } else {
        x.style.display = "none";
      }
    }

for react = const [visible, setVisible] = useState(true) here is for button <button onlick={() =>setVisible(!visible)}>hide/show

about 4 years ago · Juan Pablo Isaza Denunciar

0

here is a demo in JS, modify to what you want exactly

<ul class="ticket">
<li>
        <p>hey, I'm a P</p>
        <div class="data">I'm a Div</div>
      </li>
</ul>
.hide {display:none}

const generalBtn = document.getElementById(`btn`);
const divContainer = document.querySelector(`.ticket`);
const eachDiv = divContainer.getElementsByClassName(`data`);
generalBtn.addEventListener(`click`, () => {
  [...eachDiv].forEach((div) => {
    div.classList.toggle(`hide`);
  });
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

There is a good solution in your case but as mentioned in the comments, it needs to manipulate the filteredTickets array.

You need to add a property/value to each item of filteredTickets to track or change their state. For example, it can be isVisible property which is a boolean with false or true value.

Now, isVisible value will determine the behavior. let's modify the ticket:

const handleHideTicket = (id) => {
  // find selected ticket and ​change its visibility
 ​const updatedFilterdTickets = filteredTikcets.map(ticket => (ticket.id === id ? {...ticket, isVisible: false} : ticket))
 // now the updatedFilterdTickets need to be set in your state or general state like redux or you need to send it to the server throw a API calling.
}


return (
 ​<ul className="tickets">
   ​{filteredTickets.filter(ticket => ticket.isVisible).map((ticket) => (
     ​<li key={ticket.id} className="ticket">
       ​<h5 className="headline">{ticket.headline}</h5>
       ​<p className="text">{ticket.text}</p>
       ​<footer>
         ​<div className="data">
           ​By {ticket.address} | {new Date(ticket.time).toLocaleString()}
         ​</div>
         // add a button to control visibility of each ticket
         ​<button onClick={() => handleHideTicket (ticket.id)}> click to hid / show </button>
       ​</footer>
     ​</li>
   ​))}
 ​</ul>
);

Explanation:

a new button added to each ticket and pass the handleHideTicket handler to it. If the user clicks on this button, the handler finds that ticket and sets the isVisible property to the false.

On the other hand, we can remove the hidden tickets by applying a simple filter method before map method. so only visible tickets will be displayed.

Now, create a general button to show all the tickets. In this case, you need a handler function that sets all ticket's isVisible value to true

const handleShowAllTickets = () => {
  const updatedFilteredTickets = filteredTickets.map(ticket => ({...ticket, isVisible: true}))
  // now put the updatedFilteredTickets in your general store/post an API call/ update state 
}

Note: as I mentioned in the code's comments, you need to update your filteredTickets array after changing via handlers to reflect the changes in your elements.

about 4 years ago · Juan Pablo Isaza Denunciar
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