When I use the same id for multiple toggle buttons, the text value is not changing. However, when I use a single button, the text value changes as expected.
The toggle buttons can switch between displaying "am" or "pm."
Below is the JavaScript code I used:
$(document).ready(function(){
$('#myToggle').on('click', function () {
var text=$('#myToggle').text();
if(text === "am"){
$(this).html('pm');
} else{
$(this).text('am');
}
});
});
Here is the HTML line used for the toggle button:
<button type="button" data-toggle="collapse" href="#" id="myToggle" class="btn btn-secondary">am</button>
Check out my screenshots https://i.sstatic.net/jVacY.png.
An important note: The id value "myToggle" must be unique.