JSFiddle - React, Tailwind, and code Playground

by Alexis López Espinoza

HTML

<button id = "ejemplo" data-estado = "no">Me gusta</button>

CSS

button{
    cursor: pointer;
    background: navy;
    color: white;
    border-radius: .5em;
    font-weight: bold;
}

JavaScript

var boton = document.getElementById("ejemplo");

boton.addEventListener("click", function(){
    var estado = this.getAttribute("data-estado");

    if (estado == "no"){
        this.innerText = "Ya no me gusta";
        this.setAttribute("data-estado", "si");
        estado = "si";
    }
    else{
        this.innerText = "Me Gusta";
        this.setAttribute("data-estado", "no");
        estado = "no";
    }
}, false);