Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 22, 2019 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/3933c1b89e1141390a18f85c2193db0c to your computer and use it in GitHub Desktop.
Save parzibyte/3933c1b89e1141390a18f85c2193db0c to your computer and use it in GitHub Desktop.
// Esta función será llamada cada que se haga clic en el botón
const accionProducto = function() {
// Recuerda: "this" se refiere al elemento
const productoComoJson = this.dataset.producto;
// Debemos decodificarlo
const producto = JSON.parse(productoComoJson);
// Y ahora ya podemos acceder a las propiedades del producto
console.log("El nombre: ", producto.nombre);
console.log("El id: ", producto.id);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment