I am trying to select the saveBtn class on each button so that when I click it it saves it into local storage. However it is only saving the first instance of the selected class. Can anyone help?
html:
<div class="hour-container" id="8am">
<div class="hour"> 8 AM </div>
<textarea class="text-content"></textarea>
<button class="btn saveBtn"><i class="fas fa-save"></i></button>
</div>
js:
// Function to save the users input to the text area
function saveText() {
var textContent = $(".saveBtn").siblings(".text-content").val();
var hour = $(".saveBtn").parent().attr("id");
localStorage.setItem(hour, textContent);
console.log(textContent);
}
// Call saveText on save button click
$(".saveBtn").on("click", saveText);