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

231
Views
¿Cómo reemplazar un elemento de botón por su texto, según la consulta de medios?

Simplemente quiero eliminar el elemento <button> pero mantener el texto en el botón en un max-width: 768px usando JavaScript. Entiendo que actualmente es jQuery. Lo tengo funcionando para eliminar el botón, pero no puedo hacer que funcione la condición de consulta de medios.

Aquí está el botón, eliminado con JavaScript:

 $(".rent").replaceWith(function() { return $(this).text(); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button class="rent">Rent</button>

Esto es lo que intenté quitar el botón con una condición de consulta de medios, pero no funciona:

 const mediaQuery = window.matchMedia('(max-width: 768px)'); if (mediaQuery.matches) { $(".rent").replaceWith(function() { return $(this).text(); }); }

Aquí hay una actualización que funciona a mitad de camino con el detector de eventos, pero se rompe al cambiar el tamaño.

 function checkMediaQuery() { const mediaQuery = window.matchMedia('(max-width: 768px)'); if (mediaQuery.matches) { $(".rent").replaceWith(function() { return $(this).text(); }); } } window.addEventListener('resize', checkMediaQuery);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button class="rent">Rent</button>

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

0

Su código de reemplazo debería funcionar, solo depende de cómo y cuándo lo llame.

Aunque supongamos que aún desea que el botón haga lo que sea que haga, puede diseñar el botón para que parezca texto usando las reglas css @media .

 @media only screen and (max-width: 480px) { button.rent { background-color: transparent; border: none; } }
 <button class="rent">RENT</button>

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!