Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 19, 2019 03:26
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/5444a80c8dd7c76781bf33deceb2ee71 to your computer and use it in GitHub Desktop.
Save parzibyte/5444a80c8dd7c76781bf33deceb2ee71 to your computer and use it in GitHub Desktop.
/*
Imprimir solo algunos elementos
con JavaScript y CSS
@author parzibyte
https://parzibyte.me/blog
*/
const $btnImprimir = document.querySelector("#btnImprimir");
$btnImprimir.addEventListener("click", () => {
let ocultos = document.querySelectorAll("p,strong,h1,h2,a,button,img");
ocultos.forEach(elemento => {
elemento.classList.add("oculto-impresion");
});
let mostrados = document.querySelectorAll(".forzar-impresion");
mostrados.forEach(elemento => {
elemento.classList.remove("oculto-impresion");
});
window.print();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment