I have a total of 6 buttons that, when clicked, reveal different div
elements below them. I am looking to dynamically change the text content of each button upon being clicked. Managing this for a single button is straightforward:
<input type="checkbox" name="tabs" id="tab-one">
<label for="tab-one" id="one">Read More</label>
... and there are 5 more checkboxes with their respective labels.
var tabLabel = document.getElementById('one');
tabLabel.addEventListener("click", function() {
if (this.innerHTML=="Read More") {
this.innerHTML = "Collapse";
} else {
this.innerHTML = "Read More";
}
});
I am seeking guidance on how to adapt this JavaScript code to handle all 6 unique labels effortlessly. Any suggestions would be greatly appreciated.