RE: How to make a html javascript like button?

John Q Reviewer Asked on August 12, 2019 in Computer.
Add Comment
1 Answers
<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 => {
    e.preventDefault()
    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.