I am new to code, so please don’t be too harsh on me. I am using this code to create a button that would store and load edited data from localStorage, and make divs with the class “content” editable. Whenever I click the button, however, it only makes the first div editable. Is there a way to make it apply to all divs with the class “content”?
window.onload = function() {
if(localStorage.getItem('content')) {
document.querySelector('.content').innerHTML = localStorage.getItem('content');
}
}
let editBtn = document.querySelector('#edit_content');
let content = document.querySelector('.content');
editBtn.addEventListener('click', () => {
content.contentEditable = !content.isContentEditable;
if(content.contentEditable === 'false') {
localStorage.setItem('content', content.innerHTML);
}
});
I tried using querySelectorAll(), but that just made the button not work at all.