Edit in JSFiddle

<button data-id="11">11</button>
<button data-id="22">22</button>
<button data-id="33">33</button>
<button data-id="66">66</button>

<div id="divFavs"></div>
.fav {
  background: tomato;
}
document.body.addEventListener('click', onClick)
refresh()


function onClick(e) {
  if (!e.target.matches('button')) return

  const id = e.target.dataset.id
  const favs = JSON.parse(localStorage.getItem('favs'))

  if (favs && Array.isArray(favs)) {
    favs.push(id)
    const unique = new Set(favs)
    localStorage.setItem('favs', JSON.stringify([...unique]))
  } else {
    localStorage.setItem('favs', JSON.stringify([id]))
  }

  refresh()
}


function refresh() {
  let favs = []

  try {
    favs = JSON.parse(localStorage.getItem('favs'))
  } catch (e) {
    localStorage.removeItem('favs')
  }

  if (favs && Array.isArray(favs)) {
    divFavs.textContent = favs

    favs.forEach(id => {
      const btn = document.querySelector(`button[data-id="${id}"]`)
      if (btn) btn.classList.add('fav')
    })

  }
}