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

278
Views
Javascript - Change button text doesn't work

I have the following piece of code I need in order to update a bootstrap button when a collapsed is opened or closed. However the icon part is updating but impossible to get the button text updated and I have no idea why.

My javascript level is very low and I'm simply using part of code I might find on SOF or anywhere else on internet.

Javascript

$('#more-properties').on('hidden.bs.collapse', function () {
  var icon = document.getElementById("icon-more-properties");
  icon.setAttribute('class', 'fas fa-angle-down pr-2');

  var btn = document.getElementById("btn-more-properties");
  btn.textContent('More properties');
});
$('#more-properties').on('shown.bs.collapse', function () {
  var icon = document.getElementById("icon-more-properties");
  icon.setAttribute('class', 'fas fa-angle-up pr-2');

  var btn = document.getElementById("btn-more-properties");
  btn.textContent('Less properties');
});

Bootstrap button

<div class="col-12 text-center" id="btn-div">
    <button class="btn btn-outline-dark shadow-none collapsed" id="btn-more-properties" type="button" data-toggle="collapse" data-target="#more-properties" style="border-radius: 0 !important;">
    <i id="icon-more-properties" class="fas fa-angle-down pr-2"></i>More properties</button>
</div>

Does anyone can tell me why it is not working ? I can't find any similar issue on iternet.

Thank you in advance for your help.

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

0

that textContent is not a function but a property, so instead of calling it you need to assign the value to it:

btn.textContent = 'Less properties';

Hope this helps 🔥

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!