How to make a html javascript like button?

Reviewer Asked on August 12, 2019 in Computer,   JavaScript.
Add Comment
1 Answer(s)
<button id="like-btn" />

const elm = document.getElementById('like-btn')
const cachedText = window.localStorage.getItem('likeBtnStateText') || 'Please Like'

elm.innerHTML = cachedText

elm.addEventListener('click', e => {
    const newText = 'Thanks for Liking!'
    elm.innerHTML = newText
    window.localStorage.setItem('likeBtnStateText', newText)
    // do some other stuff
Trainee Answered on August 12, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.