favorite system without database

3

I want to make a bookmark button, like a heart or something ... the issue is that I did not want to use a database and I found a code that works and I like it but when it exits and re-enters it restarts and deletes the data:

var likes =0;
     function like(){
     document.getElementById("show").innerHTML=likes;
     likes=likes+1;
}
#button {
    background-color: #4CAF50;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}
    <!DOCTYPE html>
    <html>
    <head>
    <title>me gusta</title>
   </head>
   <body>

    <button id="button" onClick="like()">LIKE</button>
    <p type="text" style="color:blue;"id="show"></p>
    <h2>LIKES</h2>
    </body>
    </html>

How can I do it to be saved without using database?

    
asked by Alfredo Marquez 20.05.2018 в 17:34
source

1 answer

2

You can use localStorage to save

var likes =0;
     function like(){
     document.getElementById("show").innerHTML=likes;
     likes=likes+1;
localStorage.setItem('likes', likes);

}

Probably saved:

console.log(localStorage.getItem('likes'));
    
answered by 20.05.2018 / 19:07
source