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

100
Views
Quiero un botón que oculte el div y lo restaure

Quiero crear un botón que oculte cada ticket y un botón general que los restablezca a todos.

este es el codigo:

 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 answers
Answer question

0

aquí hay un ejemplo de lo que quieres! ¡Tienes que reemplazar myFunction() por tu botón y myDIV en tu elemento que deseas ocultar!

 <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) aquí está el botón <button onlick={() =>setVisible(!visible)}>hide/show

about 4 years ago · Juan Pablo Isaza Report

0

aquí hay una demostración en JS, modifique a lo que quiere exactamente

 <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 Report

0

Hay una buena solución en su caso, pero como se menciona en los comentarios, necesita manipular la matriz filteredTickets .

Debe agregar una propiedad/valor a cada elemento de filteredTickets para rastrear o cambiar su estado. Por ejemplo, puede ser la propiedad isVisible , que es un booleano con valor false o true .

Ahora, el valor de isVisible determinará el comportamiento. modifiquemos el 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> );

Explicación:

un nuevo button agregado a cada ticket y pasarle el manejador handleHideTicket . Si el usuario hace clic en este botón, el controlador encuentra ese ticket y establece la propiedad isVisible en false .

Por otro lado, podemos eliminar los tickets ocultos aplicando un método de filter simple antes del método de map . por lo que solo se mostrarán los boletos visibles.

Ahora, crea un botón general para mostrar todos los boletos. En este caso, necesita una función de controlador que establezca el valor isVisible de todos los tickets en 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 }

Nota: como mencioné en los comentarios del código, debe actualizar su matriz de filteredTickets después de cambiar a través de los controladores para reflejar los cambios en sus elementos.

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