twitter bootstrap - Change the text in a button using javascript? -


this question has answer here:

i have faq list works way : there several mini cards contain question (some text) , button (let's "see answer"). when click on button, answer question appears above button. button should not "see answer" button, "close" one. need little last part.

here have done :

<p>question</p> <div class="collapse" id="faq">     <div class="well">         answer question     </div> </div> <a class="btn" role="button" data-toggle="collapse" href="faq" aria-expanded="false" aria-controls="collapseexample">see answer</a> 

side question : since list , i'm going have several "see answer/close" buttons, i'm not allowed use id make work, ?

you can dynamically set text on button $(".btn").innerhtml = "new text displayed". put in first click(function() {...}) function.

and no, never use same id multiple elements. use classes instead. can have multiple classes on 1 element. example may have class="btn close" , use toggleclass("close") add when it's not there, remove when is.


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

Android volley - avoid multiple requests of the same kind to the server? -

magento2 - Magento 2 admin grid add filter to collection -