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

327
Views
jQuery: cambie el texto del enlace y el icono al hacer clic

Así que estoy tratando de cambiar el ícono de mi enlace para colapsar la sección junto con el texto del enlace.

Aquí está mi código:

 <a href="#collapse", class="btn", role="button", data-bs-toggle="collapse" id="btn-collapse"> <i class="material-icons" style="vertical-align: middle;">expand_more</i> <label style="vertical-align: middle;">PRIMARY TEXT</label> </a> <!--CONTENT--> <script> $(document).ready(function(){ $('#btn-collapse').on('click', function () { var text=$('#btn-collapse').text(); if(text === "SECONDARY TEXT"){ $(this).text('PRIMARY TEXT'); $(this).find("i").html("expand_more"); } else{ $(this).text('SECONDARY TEXT'); $(this).find("i").html("expand_less"); } }); }); </script>

He estado tratando de encontrar una solución para esto por un tiempo, pero nada parece funcionar. El texto cambia bien, pero el ícono desaparece por completo al hacer clic. No creo que sea un problema importante, pero hay algo que no entiendo con esto. ¿Alguna ayuda aquí sobre cómo ajustar?

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

0

 $(document).ready(function() { $('#btn-collapse').on('click', function() { var thisElement = $(this); var anchorLabelElement = thisElement.find('label'); if (anchorLabelElement.text() === "SECONDARY TEXT") { anchorLabelElement.text('PRIMARY TEXT'); thisElement.find("i").text('expand_more'); } else { anchorLabelElement.text('SECONDARY TEXT'); thisElement.find("i").text("expand_less"); } }); });
 <link href="https://cdn.jsdelivr.net/npm/material-design-icons-iconfont@6.7.0/dist/material-design-icons.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a href="#collapse" , class="btn" , role="button" , data-bs-toggle="collapse" id="btn-collapse"> <i class="material-icons" style="vertical-align: middle;">expand_more</i> <label style="vertical-align: middle;">PRIMARY TEXT</label> </a>

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!