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

193
Views
necesito ocultar un elemento cuando se muestra un texto específico

Quiero ocultar el botón de pago cuando el texto "No se encontraron opciones de envío para" está visible. Estoy seleccionando consultando todo para obtener algunos elementos, después de esto, selecciono el botón y aplico el estilo mostrar ninguno, pero aún se muestra. No sé qué estoy haciendo mal.

 function hidenv() { var txt = document.querySelectorAll(".shipping td")[0].innerText; if (txt >= "No shipping options found for") { document.querySelectorAll(".proceed-to-checkout").forEach((element) => element.style.display = "none"); } }
 <tr class="shipping"> <th>Shipment</th> <td data-title="Shipment"> No shipping options found for <strong>xxxx, xxx, 0000</strong>. </td> </tr> <div class="proceed-to-checkout"> <a href="https://nextstep.nxt/" class="checkout-button"> Proceed payment</a> </div>

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Es porque no se define ningún evento para ejecutar la función. Aquí hidenv() en la parte inferior funciona como ejecución automática en carga.

También agregue la palabra que desea hacer coincidir en un contenedor separado para que pueda recuperarse fácilmente y hacer coincidir correctamente.

 function hidenv() { var txt = document.querySelectorAll(".notFound")[0].innerText; if (txt == "No shipping options found for") { document.querySelector(".proceed-to-checkout").style.display = "none"; } } hidenv();
 <tr class="shipping"> <th>Shipment</th> <td data-title="Shipment"> <span class="notFound">No shipping options found for</span><strong> xxxx, xxx, 0000</strong>. </td> </tr> <div class="proceed-to-checkout"> <a href="https://nextstep.nxt/" class="checkout-button"> Proceed payment</a> </div>

about 4 years ago · Juan Pablo Isaza Report

0

  1. ¡Creo que depender del texto dentro de un elemento no es una buena idea! pero si realmente quieres hacerlo, ¡este es el camino!

  2. Es mejor tener div adentro y hacer que se muestre y se oculte. Ocultar un no es la mejor idea.

     let theShipmentElement = $("td[data-title='Shipment']"); if(theShipmentElement.html().indexOf('No shipping options found for') > -1){ theShipmentElement.hide(); }
about 4 years ago · Juan Pablo Isaza Report

0

@Rana ha compartido una buena respuesta, pero el texto que se muestra no tiene ninguna etiqueta html. Así que hice esto.

Primero seleccione el texto dentro de otro y luego aplique el mostrar ninguno

 function hidenv() { var txt = document.querySelector(".shipping").querySelectorAll("td")[0].innerText; if (txt === "No shipping options found for") { document.querySelector(".proceed-to-checkout").style.display = "none"; } } hidenv();
 <tr class="shipping"> <th>Shipment</th> <td data-title="Shipment"> No shipping options found for <strong>xxxx, xxx, 0000</strong>. </td> </tr> <div class="proceed-to-checkout"> <a href="https://nextstep.nxt/" class="checkout-button"> Proceed payment</a> </div>

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!