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

180
Views
Cambiar el texto del botón en jQuery

Tengo una tabla que quiero ocultar o mostrar con solo hacer clic en un botón. Además, cuando se hace clic en el botón, su texto debe cambiarse adecuadamente. Tengo el siguiente código, pero el texto del botón no se cambia:

 <script> $(document).ready(function () { $("#myButton").click(function () { $(".myTable").toggle(1000, "linear", function changeButtonText() { $("#myButton").text = ($("#myButton").text === "Hide table" ? "Show table" : "Hide table"); }); }); }); </script> ... <input type="button" id="myButton" value="Hide table" /> <table class="myTable"> ... </table>
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

No usaste la función de la manera correcta:


  • Si el elemento es botón :

Error:

 $("#myButton").text = ("new text");

Trabajar:

 $("#myButton").text("new text");

Ejemplo de trabajo:

 $("#myButton").text("New text");
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button type="button" id="myButton">Old text</button>


  • Si el elemento es input type="button" :

Error:

 $("#myButton").text = ("new text");

Trabajar:

 $("#myButton").val("new text");

Ejemplo de trabajo:

 $("#myButton").val("New text");
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="button" id="myButton" value="Hide table" />

about 4 years ago · Santiago Trujillo Report

0

Prueba esto:

 $("#myButton").val($("#myButton").val() === "Hide table" ? "Show table" : "Hide table");
about 4 years ago · Santiago Trujillo Report

0

use esto para cambiar el texto de su botón

 $("#myButton").attr('value', 'newText');
about 4 years ago · Santiago Trujillo 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!